The private and public keys are stored in ASN.1 format, conformant to PKCS #8, `Private Key Information Syntax', and the CCITT X.509 subjectPublicKeyInfo structure. The X.509 subjectPublicKeyInfo is used to store the public keys since it encodes additional information which enables recognition of the algorithm to which the public key pertains. The use of a PKCS #1 RSAPublicKey format would preclude the inclusion of any identifying information about the key algorithm.
The ASN.1 formats are as follows
PrivateKeyInfo
PrivateKeyInfo ::= SEQUENCE
{
version Version,
privateKeyAlgorithm AlgorithmIdentifier,
privateKey RSAPrivateKey,
attributes [0] IMPLICIT Attributes OPTIONAL
}
RSAPrivateKey ::= SEQUENCE
{
version Version,
modulus INTEGER,
publicExponent INTEGER,
privateExponent INTEGER,
prime1 INTEGER,
prime2 INTEGER,
exponent1 INTEGER,
exponent2 INTEGER,
coefficient INTEGER
}
Version ::= INTEGER
subjectPublicKeyInfo
SubjectPublicKeyInfo ::= SEQUENCE
{
algorithm AlgorithmIdentifier,
RSAPublicKey BIT STRING
}
RSAPublicKey ::= SEQUENCE
{
modulus INTEGER
publicExponent INTEGER
}