I've just got back into the swing of using pgp and I'm wondering how the private key is encrypted (using the passphrase to decrypt). This has got to written down somewhere, but in my searches the vast majority of answers are false positives 'How does private key crypto work?' rather than 'How is the private key encrypted by the passphrase?'

Additionally: Would it be right to say that private keys are symmetrically encrypted because it took a passphrase to encrypt it, and that same passphrase to decrypt it?

Lastly: What is the reasoning behind using a passphrase to encrypt the private key? Is it just that added layer of protection, if your private key file is compromised you are then able to revoke and reissue keys before an attacker can brute force the passphrase?


migrated from crypto.stackexchange.com Feb 12 '15 at 12:17

This question came from our site for software developers, mathematicians and others interested in cryptography.


Key pairs are generated in a number of ways, but I am going to refer to the specific example of OpenSSL, which is a very popular and easy way of creating RSA keys for many uses.

The command for creating a key used to be[1]

openssl genrsa -cipher_name -out file_name_in_pem_format key_length

Where cipher_name can be a number of symmetric encryption methods like AES, Camellia, Des3 or IDEA.

genrsa has actually been superseded by genpkey, but the same cipher options remain.

This actually answers your follow-up question. Yes, the ciphers are symmetrical so that a single password can encrypt/decrypt the key.

Finally, yes, the password is a security measure in case your private keys fall into the wrong hands. The bad guys would have to crack one more password before being able to impersonate you or your server. It might just buy you enough time to revoke the keys.

[1] https://www.openssl.org/docs/HOWTO/keys.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy