Introduction
RSA keys come in a confusing mix of formats. You have PEM files with `-----BEGIN RSA PRIVATE KEY-----` and `-----BEGIN PRIVATE KEY-----`, raw DER blobs, PKCS#1 structures that only work for RSA, and PKCS#8 wrappers that work for any algorithm. If you have ever pasted a key into a tool only to get a format error, this converter is for you. It converts RSA keys between PKCS#1 (RSAPublicKey and RSAPrivateKey), PKCS#8, SubjectPublicKeyInfo, PEM, and DER using node-forge, entirely in your browser. Paste your key, pick a target format, and the converted output appears instantly.
What this tool does
- Convert RSA private keys between PKCS#1 (`RSA PRIVATE KEY`), PKCS#8 (`PRIVATE KEY`), PEM, and DER formats using node-forge
- Convert RSA public keys between PKCS#1 (`RSA PUBLIC KEY`), SubjectPublicKeyInfo (`PUBLIC KEY`), PEM, and DER formats
- Detect the input format automatically from the PEM label or DER structure, so you do not have to specify it manually
- Preserve the modulus, public exponent, private exponent, primes, and CRT parameters across every conversion with no data loss
- Output PEM with correct RFC 7468 labels and line breaks, or DER as a hex dump for binary inspection
- Run entirely client-side: your private key never leaves your browser
How this tool works
The tool uses node-forge to parse and re-serialize RSA keys. When you paste a PEM block, it reads the `-----BEGIN ...-----` label to determine the structure. `RSA PRIVATE KEY` means a PKCS#1 RSAPrivateKey (RFC 8017). `PRIVATE KEY` means a PKCS#8 PrivateKeyInfo (RFC 5208) that wraps the PKCS#1 structure inside an AlgorithmIdentifier. `RSA PUBLIC KEY` means a bare PKCS#1 RSAPublicKey. `PUBLIC KEY` means a SubjectPublicKeyInfo (RFC 5280) that wraps the RSAPublicKey with an algorithm identifier.
For DER input, the tool attempts ASN.1 parsing to detect whether the outer structure is a SEQUENCE with version and nine integers (PKCS#1 private), a SEQUENCE with two integers (PKCS#1 public), or a SEQUENCE with an AlgorithmIdentifier and a BIT STRING (PKCS#8 or SPKI). Once the input is parsed into node-forge's internal key object, the tool re-serializes it into the target format.
For PEM output, the DER bytes are base64-encoded and wrapped at 64 characters per line with the correct RFC 7468 label. For DER output, the raw bytes are shown as a hex dump. The tool validates that the key is actually RSA before converting, and reports the modulus length in bits so you can confirm the key size (1024, 2048, 4096) survived the round trip.
All parsing and serialization happens in your browser via node-forge. No key material is transmitted to any server. This matters especially for private keys, which should never be sent over the network.
How RSA key formats work (RFC 8017, RFC 5208, RFC 5280)
RSA keys are encoded in ASN.1 (Abstract Syntax Notation One) and serialized with DER (Distinguished Encoding Rules), defined in ITU-T X.690. DER is a binary format. PEM, specified in RFC 7468, is simply base64-encoded DER wrapped in text headers like `-----BEGIN PRIVATE KEY-----`.
There are three main structures for RSA keys. PKCS#1 (RFC 8017, formerly RFC 3447) defines `RSAPublicKey` (a SEQUENCE of modulus and publicExponent) and `RSAPrivateKey` (a SEQUENCE of version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient, and optional otherPrimeInfos). PKCS#1 is RSA-specific; it cannot represent EC or Ed25519 keys.
PKCS#8 (RFC 5208) defines `PrivateKeyInfo`, a generic wrapper with an AlgorithmIdentifier and an OCTET STRING containing the algorithm-specific private key. For RSA, the OCTET STRING holds a PKCS#1 RSAPrivateKey. PKCS#8 is algorithm-agnostic, so the same outer structure works for RSA, EC, Ed25519, and X25519. Encrypted PKCS#8 (`EncryptedPrivateKeyInfo`) is defined in the same RFC.
SubjectPublicKeyInfo (SPKI) is defined in RFC 5280 (and originally X.509). It wraps an AlgorithmIdentifier and a BIT STRING containing the public key. For RSA, the BIT STRING holds a PKCS#1 RSAPublicKey. The PEM label for SPKI is `PUBLIC KEY`, while bare PKCS#1 uses `RSA PUBLIC KEY`.
The common confusion: OpenSSL's `genrsa` command historically produced PKCS#1 (`RSA PRIVATE KEY`), while `genpkey` produces PKCS#8 (`PRIVATE KEY`). Java's `RSAPrivateKeySpec` expects PKCS#1, while `PKCS8EncodedKeySpec` expects PKCS#8. This tool bridges all of them.
How to use this tool
- Paste your RSA key into the input field. PEM input should include the `-----BEGIN ...-----` and `-----END ...-----` lines. DER input should be a hex string
- The tool auto-detects the input format from the PEM label or the ASN.1 structure and parses it with node-forge
- Select the target format: PKCS#1 private, PKCS#8 private, PKCS#1 public, SPKI public, PEM, or DER
- The tool re-serializes the key into the target structure and displays the result in the output panel
- Check the reported key size in bits to confirm the modulus survived the conversion (e.g. 2048-bit)
- For PEM output, copy the result including the BEGIN and END headers. For DER output, copy the hex string
- Use the Swap button to reverse the conversion direction if you need to convert back
- Verify the round trip by converting back to the original format and confirming the output matches your input
Real-world examples
Converting PKCS#1 to PKCS#8
Input: a PEM block starting with `-----BEGIN RSA PRIVATE KEY-----` (PKCS#1, from `openssl genrsa`). Select target format PKCS#8. The output starts with `-----BEGIN PRIVATE KEY-----` and contains the same RSA key wrapped in a `PrivateKeyInfo` structure with an AlgorithmIdentifier of `1.2.840.113549.1.1.1` (rsaEncryption). The modulus and all CRT parameters are preserved. This is what Java's `PKCS8EncodedKeySpec` expects.
Converting SPKI to bare PKCS#1 public key
Input: a PEM block starting with `-----BEGIN PUBLIC KEY-----` (SubjectPublicKeyInfo, the standard format from `openssl rsa -pubout`). Select target format PKCS#1 public. The output starts with `-----BEGIN RSA PUBLIC KEY-----` and contains only the modulus and public exponent, without the AlgorithmIdentifier wrapper. Some older libraries expect this bare format.
Inspecting DER output
After converting a 2048-bit RSA private key from PEM to DER, the hex dump shows an outer SEQUENCE tag (0x30) followed by a length encoding, then the version INTEGER (0x02 0x01 0x00 for two-prime), the 256-byte modulus, and the remaining fields. You can feed this hex into an ASN.1 decoder to inspect the structure byte by byte.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| PKCS#1 (RFC 8017) | RSA-specific, minimal wrapper | OpenSSL genrsa, legacy RSA-only systems |
| PKCS#8 (RFC 5208) | Algorithm-agnostic wrapper | Java, modern OpenSSL genpkey, multi-algorithm key stores |
| SPKI (RFC 5280) | Public key with algorithm ID | X.509 certificates, standard public key format |
| PEM (RFC 7468) | Base64-encoded DER with headers | Config files, email, text-based exchange |
| DER (X.690) | Raw binary ASN.1 | TLS wire format, binary storage, hardware tokens |
Limitations or considerations
This tool converts RSA keys only. It does not handle EC, Ed25519, X25519, or DSA keys, because PKCS#1 is RSA-specific. For those algorithms, PKCS#8 and SPKI are the correct formats, but the inner structure differs and node-forge's RSA parser will reject them.
The tool does not handle encrypted PKCS#8 (`EncryptedPrivateKeyInfo`, RFC 5208 section 3). If your PEM block says `-----BEGIN ENCRYPTED PRIVATE KEY-----`, you must decrypt it first with OpenSSL (`openssl pkcs8 -nocrypt`) before pasting it here.
The tool does not validate key strength. A 512-bit or 1024-bit RSA key will convert just fine, but those key sizes are broken and should not be used for new encryption. Use at least 2048 bits, preferably 3072 or 4096 for long-term security.
Never paste a production private key into any web tool, even one that runs client-side. For production keys, use OpenSSL locally: `openssl rsa -in key.pem -out key_pkcs8.pem -topk8 -nocrypt` converts PKCS#1 to PKCS#8. This tool is for learning, testing, and development keys.
Frequently asked questions
What is the difference between RSA PRIVATE KEY and PRIVATE KEY?
`RSA PRIVATE KEY` is PKCS#1 (RFC 8017), an RSA-specific structure containing the modulus, exponents, primes, and CRT parameters. `PRIVATE KEY` is PKCS#8 (RFC 5208), a generic wrapper with an AlgorithmIdentifier and the algorithm-specific key inside. For RSA, the PKCS#8 inner key is a PKCS#1 RSAPrivateKey. OpenSSL's `genrsa` produces PKCS#1; `genpkey` produces PKCS#8.
What is the difference between PUBLIC KEY and RSA PUBLIC KEY?
`PUBLIC KEY` is SubjectPublicKeyInfo (RFC 5280), which wraps the public key with an AlgorithmIdentifier. `RSA PUBLIC KEY` is a bare PKCS#1 RSAPublicKey with just the modulus and exponent, no algorithm identifier. SPKI is the standard format used in X.509 certificates and by `openssl rsa -pubout`.
Is PEM just base64-encoded DER?
Yes. PEM (RFC 7468) is base64-encoded DER wrapped in `-----BEGIN
Can this tool convert EC or Ed25519 keys?
No. This tool handles RSA keys only, because PKCS#1 is RSA-specific. EC private keys use SEC1 (`EC PRIVATE KEY`) or PKCS#8, and Ed25519 keys use PKCS#8 or OpenSSH format. The parsing logic relies on node-forge's RSA parser, which rejects non-RSA structures.
Does the conversion change my key?
No. The conversion preserves the mathematical key material (modulus, exponents, primes, CRT parameters) exactly. It only changes the ASN.1 wrapper and the encoding (PEM vs DER). Converting back to the original format produces identical output, which you can verify with the Swap button.
Conclusion
RSA key format confusion is one of the most common practical problems in applied cryptography. Whether you are moving a key from OpenSSL to Java, from PKCS#1 to PKCS#8, or from PEM to DER, this converter handles it in your browser with no data leaving your device. For parsing and inspecting keys without converting, use the PEM Key Parser. For converting to JSON Web Key format, see the JWK Converter. For a broader format converter that handles non-RSA algorithms, try the Key Format Converter. To actually encrypt and decrypt with an RSA key, use the RSA Encrypt / Decrypt tool.