PEM Format Converter Online | PKCS#1 & PKCS#8 | X.509 Certificate

Certificates
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.

How It Works

PKCS#8 is the recommended format for all new deployments. PKCS#1 is legacy-only and implicitly assumes RSA. Always verify key metadata (algorithm, bit length) after conversion — a mismatch indicates an incompatible input. Encrypted (password-protected) keys must be decrypted with OpenSSL before conversion.

What Is PEM Format Conversion?

PEM (Privacy-Enhanced Mail) is the standard base64-encoded format for cryptographic keys and certificates. RSA keys exist in two structural formats: PKCS#1 (RSAPrivateKey, legacy) and PKCS#8 (PrivateKeyInfo, modern). X.509 certificates are always PEM-encoded. Conversion between formats re-wraps the key structure without changing the underlying key material.

When to Convert PEM Formats

  • Legacy system integration — older OpenSSL versions and embedded systems require PKCS#1 (BEGIN RSA PRIVATE KEY)
  • Modern library compatibility — cloud providers (AWS, GCP) and modern crypto libraries require PKCS#8 (BEGIN PRIVATE KEY)
  • Certificate inspection — parse X.509 fields (issuer, subject, validity, algorithm) to verify certificate identity before deployment
  • Key migration — upgrade from PKCS#1 to PKCS#8 when modernizing infrastructure
  • DER debugging — export raw DER hex for binary-level ASN.1 structure inspection

PKCS#1 vs PKCS#8 Comparison

FeaturePKCS#1PKCS#8
PEM headerBEGIN RSA PRIVATE KEYBEGIN PRIVATE KEY
Algorithm IDImplicit (RSA only)Explicit (RSA, EC, Ed25519, etc.)
StructureRSAPrivateKey (modulus, exponents, primes)PrivateKeyInfo wrapping algorithm + key
PortabilityLegacy tools, older OpenSSLModern libraries, cloud providers
RecommendationCompatibility onlyPreferred for new deployments

Standards Compliance

  • RFC 8017 — PKCS #1: RSA Cryptography Specifications
  • RFC 5208 — PKCS #8: Private-Key Information Syntax
  • RFC 5280 — Internet X.509 Public Key Infrastructure Certificate and CRL Profile
  • ASN.1 (X.680/X.690) — Abstract Syntax Notation for DER/BER encoding

Last updated:

Code Examples

OpenSSL — PKCS#8 to PKCS#1

# Convert PKCS#8 to PKCS#1 (traditional RSA format)
openssl rsa -in key.pkcs8.pem -traditional -out key.pkcs1.pem

# Convert PKCS#1 to PKCS#8
openssl pkcs8 -topk8 -nocrypt -in key.pkcs1.pem -out key.pkcs8.pem

# Inspect key structure and metadata
openssl asn1parse -in key.pkcs8.pem

OpenSSL — Certificate Analysis

# Decode X.509 certificate fields
openssl x509 -in cert.pem -text -noout

# Extract DER hex for binary inspection
openssl x509 -in cert.pem -outform DER | xxd -p

# Check certificate expiration date
openssl x509 -in cert.pem -noout -enddate

Python — Key Format Detection

from cryptography.hazmat.primitives import serialization

# Auto-detect and load a PEM key (PKCS#1 or PKCS#8)
with open("key.pem", "rb") as f:
    private_key = serialization.load_pem_private_key(f.read(), password=None)

# Export as PKCS#8 (modern default)
pkcs8_pem = private_key.private_bytes(
    serialization.Encoding.PEM,
    serialization.PrivateFormat.PKCS8,
    serialization.NoEncryption()
)

# Export as PKCS#1 (legacy RSA only)
from cryptography.hazmat.primitives.serialization import PrivateFormat
pkcs1_pem = private_key.private_bytes(
    serialization.Encoding.PEM,
    PrivateFormat.TraditionalOpenSSL,
    serialization.NoEncryption()
)

Go — PEM Decoding and Conversion

package main

import (
    "crypto/x509"
    "encoding/pem"
    "fmt"
    "os"
)

func main() {
    data, _ := os.ReadFile("key.pem")
    block, _ := pem.Decode(data)

    // Try PKCS#8 first, then fall back to PKCS#1
    key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
    if err != nil {
        rsaKey, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
        fmt.Printf("PKCS#1 RSA key, bits: %d\n", rsaKey.N.BitLen())
        return
    }
    fmt.Printf("PKCS#8 key type: %T\n", key)

    // Re-encode as PKCS#8
    pkcs8Bytes, _ := x509.MarshalPKCS8PrivateKey(key)
    pem.Encode(os.Stdout, &pem.Block{
        Type: "PRIVATE KEY", Bytes: pkcs8Bytes,
    })
}

Rust — PEM Parsing with rustls-pemfile

// Cargo: rustls-pemfile = "2", x509-parser = "0.16"
use std::fs::File;
use std::io::BufReader;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Parse PEM blocks from a certificate file
    let file = File::open("cert.pem")?;
    let reader = BufReader::new(file);
    let certs: Vec<_> = rustls_pemfile::certs(reader)
        .filter_map(|r| r.ok())
        .collect();

    if let Some(cert_der) = certs.first() {
        // Decode X.509 fields from DER bytes
        let (_, cert) = x509_parser::parse_x509_certificate(cert_der)?;
        println!("Subject: {}", cert.subject());
        println!("Issuer:  {}", cert.issuer());
        println!("Serial:  {}", cert.raw_serial());
        println!("Valid:   {} to {}",
            cert.validity().not_before, cert.validity().not_after);
    }
    Ok(())
}

Node.js — Certificate Field Extraction

const { X509Certificate } = require('crypto');
const fs = require('fs');

const pem = fs.readFileSync('cert.pem', 'utf8');
const cert = new X509Certificate(pem);

console.log('Subject:', cert.subject);
console.log('Issuer: ', cert.issuer);
console.log('Serial: ', cert.serialNumber);
console.log('Valid from:', cert.validFrom);
console.log('Valid to:  ', cert.validTo);
console.log('Key Algo: ', cert.publicKey.asymmetricKeyType);
console.log('Key Bits: ', cert.publicKey.asymmetricKeySize * 8);
console.log('SHA-256:  ', cert.fingerprint256);

Common Pitfalls

Confusing PKCS#1 with PKCS#8

PKCS#1 (BEGIN RSA PRIVATE KEY) is RSA-only and implicit. PKCS#8 (BEGIN PRIVATE KEY) wraps any algorithm with an explicit OID. Feeding a PKCS#1 key to a parser expecting PKCS#8 will fail — always check the PEM header first.

Ignoring encrypted keys

If the PEM header says "ENCRYPTED PRIVATE KEY", the key is password-protected and cannot be converted directly. Decrypt with OpenSSL first: openssl rsa -in encrypted.key -out decrypted.key.

Not verifying after conversion

Always compare the tool's metadata output (algorithm, bit length, key type) against the original key. A mismatch indicates an incompatible input format or corrupted conversion.

Assuming DER hex is portable

DER hex export is for debugging ASN.1 structure only. Different tools may encode optional fields differently (e.g., explicit vs implicit tags). Never assume DER hex from one tool will parse identically in another.

Using PKCS#1 for EC or Ed25519 keys

PKCS#1 is RSA-only. Elliptic curve keys (EC, Ed25519, X25519) must use PKCS#8 format. Attempting to convert an EC key to PKCS#1 will produce an invalid output.

Security Notes

PKCS#8 is the modern standard

PKCS#8 explicitly identifies the key algorithm via an ASN.1 OID wrapper, making it self-describing. All major cloud providers (AWS KMS, GCP KMS, Azure Key Vault) and modern libraries expect PKCS#8 input.

Browser-native processing

All conversion and parsing runs in your browser using pure TypeScript. No key material is uploaded, logged, or transmitted. The ASN.1 encoder/decoder is implemented from scratch with zero external dependencies.

Certificate chain validation

This tool parses individual certificates. For full chain validation (root → intermediate → leaf), use openssl verify -CAfile chain.pem cert.pem or an online SSL checker tool.

DER hex for debugging only

The raw DER hex export is useful for comparing against openssl asn1parse output and debugging ASN.1 structure issues. It is not a replacement for proper PEM-encoded keys in production.

Disclaimer

This PEM Format Converter tool is provided "as is" for educational and convenience purposes. While all conversion runs locally in your browser, you should independently verify converted keys before deploying them to production. Cryptographic key format errors can cause service outages — always test with openssl rsa -check or equivalent after conversion.

Further Reading

Related Concepts

Related Tools

Frequently Asked Questions

What input formats does this tool accept?

The converter accepts any PEM-encoded RSA key or X.509 certificate — including PKCS#1 private keys (BEGIN RSA PRIVATE KEY), PKCS#8 private keys (BEGIN PRIVATE KEY), SPKI public keys (BEGIN PUBLIC KEY), and certificates (BEGIN CERTIFICATE). Headers are auto-detected; just paste the full PEM block.

Can this tool analyze X.509 certificates?

Yes. Paste a PEM-encoded certificate (BEGIN CERTIFICATE) and the tool will extract key fields: version, serial number, signature algorithm, issuer, validity dates (not before / not after), subject, and public key algorithm. The raw DER hex is also available for inspection.

When should I convert between PKCS#1 and PKCS#8?

Convert to PKCS#1 when you need compatibility with legacy tools (older OpenSSL, embedded systems) that expect "BEGIN RSA PRIVATE KEY" headers. Convert to PKCS#8 when modernizing infrastructure — it is the recommended format for new deployments, explicitly identifies the key algorithm, and is required by many modern libraries and cloud providers.

Does this tool support encrypted (password-protected) keys?

No. This tool handles unencrypted PEM keys only. If your key is encrypted (the header says "ENCRYPTED PRIVATE KEY"), you must first decrypt it using OpenSSL (openssl rsa -in encrypted.key -out decrypted.key) before converting the format.

How do I verify the converted key is correct?

After conversion, compare the key metadata shown by the tool (algorithm, bit length, key type) with the original. You can also verify with OpenSSL: "openssl rsa -in converted.key -check -noout" for RSA keys. The DER hex export lets you inspect the raw ASN.1 structure for binary-level debugging.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Certificates

Learn More