Reading — step 1 of 7
Read
Key Formats: PEM, DER, OpenSSH
RSA keys are stored in standardized formats:
PEM (Privacy Enhanced Mail): base64-encoded with header/footer:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvgQNWYTJWNKGzaWlYGdLwl...
...
-----END RSA PRIVATE KEY-----
Used everywhere: TLS certs, SSH, AWS keypairs.
DER: binary (the bytes that PEM base64-encodes). Same content, different encoding.
PKCS#1: traditional RSA-only key format. PEM header: -----BEGIN RSA PRIVATE KEY-----.
PKCS#8: generic private key format (works for RSA, ECDSA, etc.). Header: -----BEGIN PRIVATE KEY-----.
OpenSSH: SSH-specific format. Public keys: ssh-rsa AAAAB3NzaC1y.... Private keys (newer): -----BEGIN OPENSSH PRIVATE KEY-----.
Conversion is a openssl one-liner:
openssl rsa -in key.pem -outform DER -out key.der # PEM -> DER
openssl rsa -in key.pem -pubout -out pub.pem # extract public from private
ssh-keygen -y -f key.pem > key.pub # PEM private -> SSH public
Inside the binary form: ASN.1 DER encoding of a SEQUENCE containing version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient. Real keys have all this for fast Chinese Remainder Theorem-based decryption.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…