Linux – How to Determine Key Length from a Keypair?

encryptionlinuxopenssl

Using OpenSSL from the command line in Linux, is there some way to examine a key (either public or private) to determine the key size?

Best Answer

openssl rsa -in private.key -text -noout

The top line of the output will display the key size.

For example:

Private-Key: (2048 bit)

To view the key size from a certificate:

$ openssl x509 -in public.pem -text -noout | grep "RSA Public Key"
RSA Public Key: (2048 bit)