Public Key Cryptography & Key Management: RSA vs ECDSA (P-256) Runbook
A complete production engineering runbook for asymmetric public-key cryptography: RSA vs Elliptic Curve (ECDSA P-256/P-384), PKCS#8 vs PKCS#1 DER containers, Web Crypto API keygen, and OpenSSL CLI management.
1. RSA Mathematical Primitives & NIST Security Margins
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out rsa_private_3072.pemGenerates an industry-standard 3072-bit RSA private key in standardized PKCS#8 format.
openssl pkey -in rsa_private_3072.pem -pubout -out rsa_public_3072.pubDerives the matching public key in standard SPKI PEM format.
openssl rsa -in rsa_private_3072.pem -text -nooutPrints human-readable modulus, prime1, prime2, and CRT exponent parameters.
| RSA Key Length | Symmetric Equivalent | Category | NIST Life Expectancy & Workload | Copy |
|---|---|---|---|---|
| 1024 bits | 80 bits of symmetric security; vulnerable to nation-state factorization | Disallowed Legacy | Completely broken for production TLS, SSH, and code signing | |
| 2048 bits | 112 bits of symmetric security; minimum acceptable TLS baseline | Legacy Production | Acceptable for existing deployments; disallowed for new US government data past 2030 | |
| 3072 bits | 128 bits of symmetric security; matching AES-128 protection level | Recommended Standard | NIST recommended baseline for systems operating through 2035+ | |
| 4096 bits | 140 bits of symmetric security; high computational signing overhead | Root Authority | Standard for long-lived offline Certificate Authority (CA) root signing keys |
2. Elliptic Curve Cryptography: ECDSA P-256 vs P-384
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ec_p256_private.pemCreates a 256-bit prime field private key providing 128-bit symmetric security.
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-384 -out ec_p384_private.pemCreates a 384-bit curve key approved for US Government CNSA Suite top secret data.
openssl pkey -in ec_p256_private.pem -pubout -out ec_p256_public.pubExports the public point (X, Y coordinates) wrapped in standard SPKI PEM syntax.
| Elliptic Curve | Field Size (Bits) | Category | Symmetric Security Equivalent | Copy |
|---|---|---|---|---|
| NIST P-256 (prime256v1) | 256 bits (32 bytes private, 65 bytes uncompressed public) | Standard WebAuthn | 128 bits symmetric security (matches RSA 3072-bit strength at 1/12th payload size) | |
| NIST P-384 (secp384r1) | 384 bits (48 bytes private, 97 bytes uncompressed public) | CNSA Suite Top Secret | 192 bits symmetric security (matches RSA 7680-bit strength with sub-millisecond sign) | |
| NIST P-521 (secp521r1) | 521 bits (66 bytes private, 133 bytes uncompressed public) | Ultra-High Entropy | 256 bits symmetric security (matches RSA 15360-bit strength) | |
| Ed25519 (RFC 8032) | 256 bits (Edwards-curve Curve25519 signature algorithm) | Modern OpenSSH | 128 bits symmetric security with deterministic nonce generation preventing RNG side-channels |
3. Key Serialization: PKCS#8, SPKI, PKCS#1 and JWK Formats
openssl pkcs8 -topk8 -inform PEM -outform PEM -in legacy_rsa.pem -out modern_pkcs8.pem -nocryptMigrates legacy -----BEGIN RSA PRIVATE KEY----- into standard -----BEGIN PRIVATE KEY-----.
openssl asn1parse -in modern_pkcs8.pemDumps the internal ASN.1 sequence headers, algorithm OIDs, and octet string boundaries.
| Key Container Format | PEM Header / Structure | Category | Standard & Interoperability | Copy |
|---|---|---|---|---|
| PKCS#8 (Private Key) | -----BEGIN PRIVATE KEY----- | RFC 5208 Universal | Algorithm-agnostic container embedding AlgorithmIdentifier OID and raw private key | |
| SPKI (Public Key) | -----BEGIN PUBLIC KEY----- | RFC 5280 Universal | Standard SubjectPublicKeyInfo used by X.509 TLS certificates and OpenSSL | |
| PKCS#1 (Legacy RSA Private) | -----BEGIN RSA PRIVATE KEY----- | Legacy RSA Specific | Restricted strictly to RSA; lacks cryptographic algorithm identifier metadata | |
| RFC 7517 JWK (JSON Web Key) | {"kty":"EC","crv":"P-256","x":"...","y":"..."} | JSON / REST APIs | Native format for OAuth 2.0 / OpenID Connect JWKS endpoints and browser WebCrypto |
4. Zero-Telemetry In-Browser Key Generation with Web Crypto
const keyPair = await window.crypto.subtle.generateKey(
{ name: "ECDSA", namedCurve: "P-256" },
true,
["sign", "verify"]
);
const spki = await window.crypto.subtle.exportKey("spki", keyPair.publicKey);
console.log("SPKI Bytes:", new Uint8Array(spki).byteLength);Asynchronous in-browser EC keypair generation with non-extractable or extractable export.
| SubtleCrypto Method | Algorithm Parameter | Category | Security Boundary | Copy |
|---|---|---|---|---|
| generateKey | RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, or ECDSA | Key Synthesis | Generates cryptographically random key material using OS entropy pools | |
| exportKey (pkcs8) | Exports private key as raw ArrayBuffer in PKCS#8 DER binary format | Binary Serialization | Requires extractable: true flag during initial key generation | |
| exportKey (spki) | Exports public key as raw ArrayBuffer in SPKI DER binary format | Public Distribution | Public keys can always be exported regardless of private key extractability | |
| exportKey (jwk) | Exports key material directly as structured RFC 7517 JSON object | Cloud JSON Integration | Enables immediate serialization into OpenID Connect .well-known/jwks.json |
5. Key Storage, Rotation & Filesystem Hardening
chmod 600 private_key.pemRestricts read and write permissions exclusively to the owner UID.
ssh-add -t 28800 ~/.ssh/id_ed25519Loads key into memory for 8 hours (28800s) then automatically purges key material.
openssl pkey -in public_key.pub -pubin -outform DER | openssl dgst -sha256Calculates the canonical SHA-256 fingerprint for identity auditing.
| Storage Environment | Recommended Protection | Category | Compromise Risk & Mitigation | Copy |
|---|---|---|---|---|
| Local Workstation (Disk) | chmod 600; isolate inside ~/.ssh with passphrase encryption | Filesystem Boundary | Prevents local unprivileged processes from scraping private keys | |
| Continuous Integration (CI/CD) | Store in GitHub Actions Secrets or Vault; never hardcode in repo | Pipeline Secrets | Mask secrets in CI stdout logs; rotate keys immediately if leaked | |
| Production Microservice (RAM) | Inject via environment variables or mounted tmpfs memory volume | Runtime Memory | Avoids writing plaintext keys to durable block storage volumes | |
| Cloud Secret Manager (Vault) | AWS KMS, Google Cloud Secret Manager, or HashiCorp Vault | Enterprise Secret Vault | Enforces automated 90-day rotation, audit logs, and IAM role access barriers |
Related Free Online Tools
Put these techniques into practice immediately with our privacy-first browser utilities:
Generate cryptographically secure RSA key pairs (2048 to 4096-bit) client-side with PKCS#8 and SPKI PEM export.
Generate NIST P-256, P-384, and P-521 elliptic curve key pairs with PKCS#8 PEM and RFC 7517 JSON Web Key export.
Inspect and parse X.509 PEM certificates locally in-browser with Subject, Issuer, SANs, and fingerprint extraction.