Aller au contenu
uencoder

RSA Clé Formats Référence

PEM, DER, PKCS#1, PKCS#8, et OpenSSH formats pour RSA public et privé clés.

Encoding Containers

RSA keys are serialized in either binary DER or Base64-encoded PEM wrapped in header lines. DER is compact and used by protocols that transport binary, while PEM is human-readable and common in configuration files. The PEM header line identifies the key type, such as BEGIN RSA PRIVATE KEY or BEGIN PUBLIC KEY. Tools must inspect both the header and the ASN.1 structure to interpret a key correctly.

PKCS#1
Traditional RSA-specific format, header RSA PRIVATE KEY
BEGIN RSA PRIVATE KEY
PKCS#8
Generic private key envelope, header PRIVATE KEY
BEGIN PRIVATE KEY
SubjectPublicKeyInfo
Generic public key envelope, header PUBLIC KEY
BEGIN PUBLIC KEY
OpenSSH
Base64 single-line format for authorized_keys
ssh-rsa AAAA...

ASN.1 Structures

Under the PEM encoding, keys are ASN.1 DER sequences of integers. A PKCS#1 private key contains version, modulus, public exponent, private exponent, and CRT parameters. PKCS#8 wraps the PKCS#1 structure in an algorithm identifier and optional attributes. Parsing errors often stem from confusing PKCS#1 and PKCS#8 formats, which share the same PEM extension but different inner structures.

Conversion and Interop

Converting between formats is a frequent task when moving keys across toolchains. OpenSSL commands like rsa and pkcs8 convert between PKCS#1 and PKCS#8 private keys. The OpenSSH format uses a custom binary layout inside its Base64 that differs from PKCS standards. When in doubt, inspect the PEM header line first and use a parser that auto-detects the structure rather than assuming a fixed format.

Outils associés

参考链接