key generation should be done, need to finish packing/formatting. also need to start on moduli generation.
24 lines
493 B
Go
24 lines
493 B
Go
package sshkeys
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
)
|
|
|
|
func (k *SSHPrivKey) generateRsa() error {
|
|
if k.BitSize == 0 {
|
|
k.BitSize = defRSABitSize
|
|
}
|
|
if k.Key != nil || k.PublicKey.Key != nil {
|
|
return nil // A no-op; key already exists.
|
|
}
|
|
if sk, err := rsa.GenerateKey(rand.Reader, int(k.BitSize)); err != nil {
|
|
return err
|
|
} else {
|
|
k.Key = sk // See https://golang.org/pkg/crypto/rsa/#PrivateKey
|
|
k.PublicKey.KeyType = KeyRsa
|
|
k.PublicKey.Key = k.Key.PublicKey
|
|
}
|
|
return nil
|
|
}
|