SSHSecure/sshkeys/rsa.go
brent s 86266685f5
checking in for the night.
key generation should be done, need to finish packing/formatting.

also need to start on moduli generation.
2020-09-18 04:04:39 -04:00

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
}