@@ -88,9 +88,11 @@ func bytesToKeys(private []byte, passphrase string, publics [][]byte) (crypto.Pr
8888// so the same passphrase will always generate the same key, this is useful if you don't want to backup the key,
8989// but it's less secure, you must use a strong passphrase.
9090func GenerateKeyFile (deterministic bool , privateKeyPath , comment , passphrase string ) error {
91+ var prvKeyPem * pem.Block
92+
9193 seed := rand .Reader
9294
93- if deterministic {
95+ if passphrase != "" && deterministic {
9496 salt := sha256 .Sum256 ([]byte (passphrase ))
9597 derivedKey := argon2 .IDKey ([]byte (passphrase ), salt [:], 128 , 64 * 1024 , 4 , 32 )
9698 seed = hkdf .New (sha256 .New , derivedKey , nil , nil )
@@ -116,7 +118,11 @@ func GenerateKeyFile(deterministic bool, privateKeyPath, comment, passphrase str
116118 return err
117119 }
118120
119- prvKeyPem , err := ssh .MarshalPrivateKeyWithPassphrase (privateKey , comment , []byte (passphrase ))
121+ if passphrase != "" {
122+ prvKeyPem , err = ssh .MarshalPrivateKeyWithPassphrase (privateKey , comment , []byte (passphrase ))
123+ } else {
124+ prvKeyPem , err = ssh .MarshalPrivateKey (privateKey , comment )
125+ }
120126 if err != nil {
121127 return err
122128 }
0 commit comments