I am trying to verify my understanding related to some aspects of RSA public key encoding.
First, here is my line of thoughts, please correct me if I am wrong:
Let's say we have a X.509 certificate, which contains a RSA public key inside. The certificate contains the RSA public key in the DER format (octets representing the modulus and exponent), as far as my understanding goes.
And now the question: Is there a way to tell if the public key contained in the x.509 certificate is in PKCS1 or another format?
There is no way I could tell if the public key contained in the x.509 certificate is in PKCS1 or another format, as it is not in PEM format, right?
The certificate contains the public key in what is now called the SubjectPublicKeyInfo format (which as a standalone concept gets the PEM name "PUBLIC KEY"), because that's the data type from the spec:
TBSCertificate ::= SEQUENCE {
<snip />
subjectPublicKeyInfo SubjectPublicKeyInfo,
<snip />
}
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING }
The SubjectPublicKeyInfo.algorithm
value concurrently identifies the format of the data in SubjectPublicKeyInfo.subjectPublicKey
and the algorithm that key uses.
From IETF RFC 3279 we learn
The OID rsaEncryption identifies RSA public keys.
pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1}
The rsaEncryption OID is intended to be used in the algorithm field of a value of type AlgorithmIdentifier. The parameters field MUST
have ASN.1 type NULL for this algorithm identifier.The RSA public key MUST be encoded using the ASN.1 type RSAPublicKey:
RSAPublicKey ::= SEQUENCE { modulus INTEGER, -- n publicExponent INTEGER } -- e
where modulus is the modulus n, and publicExponent is the public
exponent e. The DER encoded RSAPublicKey is the value of the BIT
STRING subjectPublicKey.
So, RSA keys, identified by the OID 1.2.840.113549.1.1.1, use the RSAPublicKey format which was originally defined in the spec called PKCS#1.