←Back to Guides
๐Ÿ”‘Public Key Infrastructureโฑ๏ธ 14 min read•Updated November 2026

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.

#Cryptography#RSA#ECDSA#P-256#PKCS8#SPKI#OpenSSL#WebCrypto#Security

1. RSA Mathematical Primitives & NIST Security Margins

RSA relies on the mathematical difficulty of factoring composite semiprime integers n = p * q into their large prime factors. As computational hardware and General Number Field Sieve (GNFS) algorithms advance, minimum key lengths must scale aggressively. NIST SP 800-57 guidelines deprecate RSA keys under 2048 bits for all digital signatures and recommend 3072-bit keys for systems operating past 2030.
Generate 3072-bit RSA Private Key via OpenSSL
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out rsa_private_3072.pem

Generates an industry-standard 3072-bit RSA private key in standardized PKCS#8 format.

Extract SubjectPublicKeyInfo (SPKI) Public Key
openssl pkey -in rsa_private_3072.pem -pubout -out rsa_public_3072.pub

Derives the matching public key in standard SPKI PEM format.

Inspect Modulus, Primes & Exponents (ASN.1 Text)
openssl rsa -in rsa_private_3072.pem -text -noout

Prints human-readable modulus, prime1, prime2, and CRT exponent parameters.

RSA Key LengthSymmetric EquivalentCategoryNIST Life Expectancy & WorkloadCopy
1024 bits80 bits of symmetric security; vulnerable to nation-state factorizationDisallowed LegacyCompletely broken for production TLS, SSH, and code signing
2048 bits112 bits of symmetric security; minimum acceptable TLS baselineLegacy ProductionAcceptable for existing deployments; disallowed for new US government data past 2030
3072 bits128 bits of symmetric security; matching AES-128 protection levelRecommended StandardNIST recommended baseline for systems operating through 2035+
4096 bits140 bits of symmetric security; high computational signing overheadRoot AuthorityStandard for long-lived offline Certificate Authority (CA) root signing keys

2. Elliptic Curve Cryptography: ECDSA P-256 vs P-384

Elliptic Curve Cryptography (ECC) bases its trapdoor function on the Elliptic Curve Discrete Logarithm Problem (ECDLP) over finite prime fields. Because point multiplication is significantly harder to reverse than integer factorization, ECC delivers equivalent cryptographic security at dramatically reduced key lengths and transmission payload sizes.
Generate NIST P-256 (secp256r1) Key Pair via OpenSSL
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ec_p256_private.pem

Creates a 256-bit prime field private key providing 128-bit symmetric security.

Generate NIST P-384 (CNSA Suite) Key Pair
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-384 -out ec_p384_private.pem

Creates a 384-bit curve key approved for US Government CNSA Suite top secret data.

Extract Elliptic Curve Public Key Points
openssl pkey -in ec_p256_private.pem -pubout -out ec_p256_public.pub

Exports the public point (X, Y coordinates) wrapped in standard SPKI PEM syntax.

Elliptic CurveField Size (Bits)CategorySymmetric Security EquivalentCopy
NIST P-256 (prime256v1)256 bits (32 bytes private, 65 bytes uncompressed public)Standard WebAuthn128 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 Secret192 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 Entropy256 bits symmetric security (matches RSA 15360-bit strength)
Ed25519 (RFC 8032)256 bits (Edwards-curve Curve25519 signature algorithm)Modern OpenSSH128 bits symmetric security with deterministic nonce generation preventing RNG side-channels

3. Key Serialization: PKCS#8, SPKI, PKCS#1 and JWK Formats

Cryptographic keys must be serialized into portable standard structures before transmission or persistence on disk. Legacy tools historically used algorithm-specific headers (PKCS#1 for RSA, SEC1 for EC). Modern production engineering standardizes on PKCS#8 (RFC 5208) for private keys, SPKI (RFC 5280) for public keys, and RFC 7517 JWK for web identity APIs.
Convert Legacy PKCS#1 RSA Key to Standard PKCS#8
openssl pkcs8 -topk8 -inform PEM -outform PEM -in legacy_rsa.pem -out modern_pkcs8.pem -nocrypt

Migrates legacy -----BEGIN RSA PRIVATE KEY----- into standard -----BEGIN PRIVATE KEY-----.

Inspect ASN.1 DER Structural Nodes
openssl asn1parse -in modern_pkcs8.pem

Dumps the internal ASN.1 sequence headers, algorithm OIDs, and octet string boundaries.

Key Container FormatPEM Header / StructureCategoryStandard & InteroperabilityCopy
PKCS#8 (Private Key)-----BEGIN PRIVATE KEY-----RFC 5208 UniversalAlgorithm-agnostic container embedding AlgorithmIdentifier OID and raw private key
SPKI (Public Key)-----BEGIN PUBLIC KEY-----RFC 5280 UniversalStandard SubjectPublicKeyInfo used by X.509 TLS certificates and OpenSSL
PKCS#1 (Legacy RSA Private)-----BEGIN RSA PRIVATE KEY-----Legacy RSA SpecificRestricted strictly to RSA; lacks cryptographic algorithm identifier metadata
RFC 7517 JWK (JSON Web Key){"kty":"EC","crv":"P-256","x":"...","y":"..."}JSON / REST APIsNative format for OAuth 2.0 / OpenID Connect JWKS endpoints and browser WebCrypto

4. Zero-Telemetry In-Browser Key Generation with Web Crypto

Modern browsers provide high-performance hardware-backed cryptographic primitives via window.crypto.subtle. Because Web Crypto executes directly in the client V8/SpiderMonkey runtime sandbox without network requests, developers can generate production-grade keys locally without exposing secrets to cloud endpoints.
Generate ECDSA P-256 Key Pair via JavaScript WebCrypto
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 MethodAlgorithm ParameterCategorySecurity BoundaryCopy
generateKeyRSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, or ECDSAKey SynthesisGenerates cryptographically random key material using OS entropy pools
exportKey (pkcs8)Exports private key as raw ArrayBuffer in PKCS#8 DER binary formatBinary SerializationRequires extractable: true flag during initial key generation
exportKey (spki)Exports public key as raw ArrayBuffer in SPKI DER binary formatPublic DistributionPublic keys can always be exported regardless of private key extractability
exportKey (jwk)Exports key material directly as structured RFC 7517 JSON objectCloud JSON IntegrationEnables immediate serialization into OpenID Connect .well-known/jwks.json

5. Key Storage, Rotation & Filesystem Hardening

Private keys are only as secure as their storage boundary. Committing private keys to Git repositories, leaving keys with permissive 644 read permissions, or failing to plan automated rotation cycles are the leading causes of production cryptographic breaches.
Enforce Strict 600 Permissions on Private Keys
chmod 600 private_key.pem

Restricts read and write permissions exclusively to the owner UID.

Add Key to In-Memory SSH Agent with Lifetime Limit
ssh-add -t 28800 ~/.ssh/id_ed25519

Loads key into memory for 8 hours (28800s) then automatically purges key material.

Compute SHA-256 Public Key Fingerprint
openssl pkey -in public_key.pub -pubin -outform DER | openssl dgst -sha256

Calculates the canonical SHA-256 fingerprint for identity auditing.

Storage EnvironmentRecommended ProtectionCategoryCompromise Risk & MitigationCopy
Local Workstation (Disk)chmod 600; isolate inside ~/.ssh with passphrase encryptionFilesystem BoundaryPrevents local unprivileged processes from scraping private keys
Continuous Integration (CI/CD)Store in GitHub Actions Secrets or Vault; never hardcode in repoPipeline SecretsMask secrets in CI stdout logs; rotate keys immediately if leaked
Production Microservice (RAM)Inject via environment variables or mounted tmpfs memory volumeRuntime MemoryAvoids writing plaintext keys to durable block storage volumes
Cloud Secret Manager (Vault)AWS KMS, Google Cloud Secret Manager, or HashiCorp VaultEnterprise Secret VaultEnforces automated 90-day rotation, audit logs, and IAM role access barriers

๐ŸŽ“Explore More Guides

โœจ