RSA key formats: PKCS#1 vs PKCS#8 vs SPKI
An RSA key is just a set of numbers, but those numbers get wrapped in several different encodings, and software is picky about which one it accepts. The good news is you can tell them apart at a glance from the PEM header line.
Reading the header
-----BEGIN RSA PRIVATE KEY-----is PKCS#1: the original RSA-specific private key format.-----BEGIN PRIVATE KEY-----is PKCS#8: a newer, algorithm-agnostic wrapper that can hold RSA, EC, or other key types. It is the modern default.-----BEGIN ENCRYPTED PRIVATE KEY-----is PKCS#8 with the key material encrypted under a passphrase.-----BEGIN PUBLIC KEY-----is SPKI (SubjectPublicKeyInfo): the standard public key format, again algorithm-agnostic.-----BEGIN RSA PUBLIC KEY-----is the older PKCS#1 public key form.
The header is not decoration; it tells the parser how to read the bytes inside. A library expecting PKCS#8 will reject a PKCS#1 body even though the underlying key is identical.
What is actually inside
All of these are ASN.1 structures encoded with DER, then Base64 wrapped into PEM. The difference is the outer envelope. PKCS#1 holds the raw RSA numbers directly: modulus, public exponent, private exponent, and the primes. PKCS#8 wraps that same key inside an extra layer that names the algorithm first, so a single parser can handle RSA, ECDSA, or Ed25519 without knowing in advance which it is reading. SPKI does the same algorithm-tagging trick for public keys. That is the whole reason the newer formats exist: one code path for every key type.
Why you end up converting
Different ecosystems standardized on different formats. OpenSSL historically emitted PKCS#1; most modern languages and libraries (Java, Node's WebCrypto, Go) expect PKCS#8 private keys and SPKI public keys. So a key that works perfectly in one tool throws a parse error in another, purely because of the wrapper. A frequent symptom is a WebCrypto importKey call that fails on a BEGIN RSA PRIVATE KEY block until you re-wrap it as PKCS#8.
The equivalent OpenSSL commands
The conversions are mechanical re-encodings:
# PKCS#1 to PKCS#8
openssl pkcs8 -topk8 -nocrypt -in pkcs1.pem -out pkcs8.pem
# PKCS#8 back to PKCS#1
openssl rsa -in pkcs8.pem -out pkcs1.pem
# Extract the SPKI public key from either
openssl rsa -in pkcs8.pem -pubout -out public.pem
The conversion is lossless and reversible: the same key numbers are simply re-wrapped. Converting PKCS#1 to PKCS#8 does not weaken or change the key, it just relabels how it is stored. The one thing that does change the bytes is adding or removing passphrase encryption, which is a separate step from the format itself.
A note on DER versus PEM
Everything above assumed PEM, the Base64 text form. The same structures also exist as raw binary DER, often with a .der or .key extension and no readable header. If a file looks like binary garbage rather than -----BEGIN, it is probably DER, and the fix is a format conversion rather than a different key.
Doing it without leaking the key
A private key should never be pasted into a server you do not control. The RSA Key Converter re-encodes between PKCS#1, PKCS#8, and SPKI in your browser, so the key stays on your machine. If you are converting full certificate bundles rather than bare keys, see convert SSL certificate formats, and to confirm a key and certificate belong together after converting, does my private key match my certificate walks through the check.