1. The Frustration of Header Mismatches
Every developer who has configured an AWS EC2 instance, an Nginx reverse proxy, or a JWT signing service has run into the dreaded error: error:0906D06C:PEM routines:PEM_read_bio:no start line or Invalid key format. The root cause is almost always a mismatch between PKCS#1 and PKCS#8.
2. PKCS#1 (The RSA-Specific Format)
PKCS#1 is the traditional cryptographic specification tailored exclusively for RSA. Because it only supports RSA, it does not need to declare which algorithm is inside the payload.
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA0Y1W...
-----END RSA PRIVATE KEY-----
Underneath the Base64 encoding, PKCS#1 directly serializes the RSA components as an ASN.1 SEQUENCE of integers: { version, modulus n, publicExponent e, privateExponent d, prime1 p, prime2 q, exponent1, exponent2, coefficient }.
3. PKCS#8 (The Universal Modern Standard)
PKCS#8 was introduced to create a single, unified container format for any private key type (RSA, Elliptic Curves, Ed25519, DSA).
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD...
-----END PRIVATE KEY-----
Notice the absence of the word RSA. A PKCS#8 file wraps the private key inside a metadata structure that explicitly specifies the algorithm via an Object Identifier (OID): 1.2.840.113549.1.1.1 (rsaEncryption). Web Crypto API and modern libraries default strictly to PKCS#8.
4. Public Key Formats: SPKI vs. PKCS#1
| Header Banner | Specification | Algorithm Support | Typical Consumer |
|---|---|---|---|
| BEGIN RSA PUBLIC KEY | PKCS#1 | RSA Only | Legacy OpenSSL, C libraries |
| BEGIN PUBLIC KEY | X.509 SubjectPublicKeyInfo (SPKI) | Universal (RSA, ECC, Ed25519) | Browsers, Node.js, Web Crypto, Java |
| ssh-rsa AAAAB3Nza... | OpenSSH Public Key | Single line format | ~/.ssh/authorized_keys, GitHub |
5. OpenSSL One-Liner Conversions
To convert from legacy PKCS#1 to modern PKCS#8:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in pkcs1_private.pem -out pkcs8_private.pem
To convert from modern PKCS#8 back to legacy PKCS#1:
openssl rsa -in pkcs8_private.pem -out pkcs1_private.pem
Written by Elena Rostov
Elena has designed secure document and PKI pipelines across banking and enterprise distributed systems.