We need ways to distribute our public keys, private keys and digital certificates in a portable format. One of the most common forms is Distinguished Encoding Rules (DER) encoding of ASN.1. Overall it is truly binary representation of the encoded data. The other common format is PEM, and which converts the binary encoding into a text readable format. With PEM we can encode cryptographic infromation in a Base64 ASCII format and with plain-text headers and footers of "-----BEGIN RSA PRIVATE KEY-----" and "-----END RSA PRIVATE KEY-----", whereas with DER we have binary format. In this page, we will read in a DER encoded hex string and determine its contents. Note that with Ed25519 and Ed448 only uses an x co-ordinate and not an (x,y) co-ordinate.
ASN.1: DER and PEM formats |
Notes:
Ex 1 key is:
0x2927B10512BAE3EDDCFE467828128BAD2903269919F7086069C8C4DF6C732838C7787964EAAC00E5921FB1498A60F4606766B3D9685001558D1A974E7341513E
Ex 2 key is
0xB838FF44E5BC177BF21189D0766082FC9D843226887FC9760371100B7EE20A6FF0C9D75BFBA7B31A6BCA1974496EEB56DE357071955D83C4B1BADAA0B21832E9
Ex 3 key is split up as:
0xb'0030480241 00A79850DEEDE08E51270555AC9EA15623E22F902058FCDB87383CCA46CA886AD6F95F6DCB7ED34198EB2CE07BC7459D1F4EBCCE43C87147EBD263A67ABAA8B339 0203 010001'
gives a private exponent of:
0x00A79850DEEDE08E51270555AC9EA15623E22F902058FCDB87383CCA46CA886AD6F95F6DCB7ED34198EB2CE07BC7459D1F4EBCCE43C87147EBD263A67ABAA8B339
and a public exponent of:
0x010001
Ex 4 key is split up as:
0xb'00308189028181 00A399CAF6D93B62A6B6A5311EFE93C4D647397CA05A98FA5CDDB72D6816AB16FC85F940EFE9CF2233975C8925C60F4CD356767CC8445686313A0CAEAE32930070CA90591A1B249C2FCEF9280F5A11D8F1990579D86A05B2523F52C4A876DA2D635CA27FBFF195E6F7015F834928F033A20B2CD0216A852958B3E58D0F9BD54233 0203 010001'
gives a private exponent of:
ox00A399CAF6D93B62A6B6A5311EFE93C4D647397CA05A98FA5CDDB72D6816AB16FC85F940EFE9CF2233975C8925C60F4CD356767CC8445686313A0CAEAE32930070CA90591A1B249C2FCEF9280F5A11D8F1990579D86A05B2523F52C4A876DA2D635CA27FBFF195E6F7015F834928F033A20B2CD0216A852958B3E58D0F9BD54233
and a public exponent of:
0x010001
Theory
One of the great things about cryptography is the way we have managed to migrate our methods. This migration is often required when we introduce new methods (such as with ECC) or where methods are deprecated (such as for DES). We thus have ways to define new methods and which can be easily interpreted by applications. At the core of this is the DER format for defining our cryptography.
We need ways to distribute our public keys, private keys and digital certificates in a portable format. One of the most common forms is Distinguished Encoding Rules (DER) encoding of ASN.1 (Abstract Syntax Notation One). Overall it is a truly binary representation of the encoded data. The other common format is PEM, and which converts the binary encoding into a text readable format. With PEM we can encode cryptographic information in a Base64 ASCII format and with plain-text headers and footers of “ — — -BEGIN RSA PRIVATE KEY — — -” and “ — — -END RSA PRIVATE KEY — — -”, whereas with DER we have binary format.
This page will look at the DER format and has code to decode a hex string and into its contents. Overall ASN.1 is used to define abstract types and values. One of the most basic types is SEQUENCE and is an ordered collection of one or more types. In DER, SEQUENCE is identified with a tag of “30”, and followed by a byte value for the length of the object defined. The other common types are OBJECT IDENTIFIER (and which has a tag of “06”) and BIT STRING (and which has a tag of “03”).
The object identifier tag is used to define the cryptography methods used. An example identifier for ECC encryption is “1.2.840.10045.2.1”, and where 1 is OSI, 2 is member body, 840 is US (ANSI), and 10045 is “ansi-X9–62”, and “2” is key type [1]. Other common algorithms are: “1.2.840.113549.1.1.1” (X509 RSA), “1.2.840.10040.4.1” (X509 Digital Signature Standard -DSS), and “1.2.840.10046.2.1” (Diffie-Hellman — DH). The following is an example of the hex sequence for an object ID, and where we have the “06” tag, followed by an identifier for seven bytes (“07”), and then the Object ID of seven bytes (“2a8648ce3d0201”):
06 07 2a8648ce3d0201 # Object ID - 7 bytes long - 1.2.840.10045.2.1 (ECC)
We can also define the curve type in the object identifier, and where we have the form of iso(1), member-body(2), us(840), ansi-X9–62(10045), curves(3), prime(1). For example, 1.2.840.10045.3.1.7 defines ECDSA P-256. Other examples are SECP192R1 (“1.2.840.10045.3.1.1”), SECP224R1 (“1.3.132.0.33”), SECP256K1 (“1.3.132.0.10”), SECP256R1 (“1.2.840.10045.3.1.7”), SECP384R1 (“1.3.132.0.34”), SECP521R1 (“1.3.132.0.35”), and BRAINPOOLP256R1 (“1.3.36.3.3.2.8.1.1.7”). An example where we have an identifier (“06”), followed by the number of bytes identifier (“08”) and Object ID of eight bytes (“2a8648ce3d030107”):
06 08 2a8648ce3d030107 # Object ID - 8 bytes long - 1.2.840.10045.3.1.7 (ECDSA P256)For the “03” tag, we define a bitstream for keys. In the following, we have “03”, followed by the number of bytes (66 bytes) for the keys, and then the keys are defined after this (64 bytes):
03 42 # Bit stream - 0x42 (66 bytes long) 0004 # Identifies public key 2927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838 # Identifies public key x co-ordinate c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e # Identifies public key y co-ordinate
An example hex string for a DER format for ECC public keys is:
3059301306072a8648ce3d020106082a8648ce3d030107034200042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513
We can then break down with:
30 59 # Sequence length 0x59 - 91 bytes long 30 13 # Sequence length 0x13 - 21 bytes long 06 07 2a8648ce3d0201 # Object ID - 7 bytes long - 1.2.840.10045.2.1 (ECC) 06 08 2a8648ce3d030107 # Object ID - 8 bytes long - 1.2.840.10045.3.1.7 (ECDSA P256) 03 42 # Bit stream - 0x42 (66 bytes long) 0004 # Identifies public key 2927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838 # Identifies public key x co-ordinate c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e # Identifies public key y co-ordinate
If we need to convert a DER into a hex format, we can just use "xxd" and "tr":
% xxd -plain 512b-rsa-example-keypair.der | tr -d '\n' 3082013b0201000241009bfc6690798442bbab13fd2b7bf8de1512e5f193e3068a7bb8b1e19e26bb9501bfe730ed648502dd1569a834b006ec3f353c1e1b2b8ffa8f001bdf07c6ac5307020301000102401b4af77b31f7e56146d6d1866943ab400eb5732688239dd9760091d4853c6f1ec051ebe6905b417fe6aa316bac59539626f1aedabe55a47540225f2717a0d291022100c8c4277cd561adbf328e1ecbe894f49f5577e5a8c970d00f8104b709b21b53e9022100c6e665be10c86db71eee8e41bce867099d8dee461bd590b9ee0dc5f9c6c9c96f0221009bb0318706da36a89c85c5b00eeee43c6345151dad0904efe0f74d1201c25b71022046d1258c84a1381f290e3aec40fc6623504b8678c3d448514ae6f0843c3900550221008d036e290ed74e1f2770b52079fb316a14b7e6559a6540cfe0e646f8b28ef4630a
In OpenSSL, we can convert from DER to PEM with:
openssl x509 -inform der -in mycert.der -out mycert.pem
and:
openssl x509 -outform der -in mycert.pem -out mycert.der
An example of a public key is:
-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw51PMBm2psyIjHPU1efH Ulyh22zy3hEhlsNPH6/Cqg0HJorX1WbNKLfiU2aAt24jn4CC+y8PusrmMMCIca5x 0L4XZxm14QvKKImIOMOMblS1Te29n64HuuQ9owKLHuSMww4wiLiY/nAvjK/5/kKT HL6x7nK/Pq72eoQ/etFBkaX5nYGUD/+G+5BgAPx1mBgU5/y9+/+QZ9xbYU6zogOW Tfa6rDMSAbmJOtkk1ghnuaq4dSoHWbW+zpHMVtjtHgzDGhX9KjOmvSDQIGn4wevD p2yDLULUbsdO4ylacTkxyIc92ZHdZeP6Hh+KhNC04Z65zwXLEA3M4bucX+u6nszW xwIDAQAB -----END PUBLIC KEY-----
Code
The code used is:
import asn1 import binascii from pem import class_id_to_string,tag_id_to_string,value_to_string import sys import base64 der='3059301306072a8648ce3d020106082a8648ce3d030107034200042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e' der='305c300d06092a864886f70d0101010500034b003048024100a79850deede08e51270555ac9ea15623e22f902058fcdb87383cca46ca886ad6f95f6dcb7ed34198eb2ce07bc7459d1f4ebcce43c87147ebd263a67abaa8b3390203010001' der='3059301306072a8648ce3d020106082a8648ce3d030107034200042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e' der="-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKSexBRK64+3c/kZ4KBKLrSkDJpkZ9whgacjE32xzKDjHeHlk6qwA5ZIfsUmKYPRgZ2az2WhQAVWNGpdOc0FRPg==-----END PUBLIC KEY-----" der="305c300d06092a864886f70d0101010500034b003048024100a79850deede08e51270555ac9ea15623e22f902058fcdb87383cca46ca886ad6f95f6dcb7ed34198eb2ce07bc7459d1f4ebcce43c87147ebd263a67abaa8b3390203010001" der="30819f300d06092a864886f70d010101050003818d0030818902818100a399caf6d93b62a6b6a5311efe93c4d647397ca05a98fa5cddb72d6816ab16fc85f940efe9cf2233975c8925c60f4cd356767cc8445686313a0caeae32930070ca90591a1b249c2fcef9280f5a11d8f1990579d86a05b2523f52c4a876da2d635ca27fbff195e6f7015f834928f033a20b2cd0216a852958b3e58d0f9bd542330203010001" indent=0 if (len(sys.argv)>1): der=str(sys.argv[1]) def make_pem(st): bff="-----BEGIN PUBLIC KEY-----\n" bff=bff+base64.b64encode(st).decode()+"\n" bff=bff+"-----END PUBLIC KEY-----\n" print (bff) def read_pem(data): """Read PEM formatted input.""" data = data.replace("\n","") data = data.replace("","") data = data.replace("-----BEGIN PUBLIC KEY-----","") data = data.replace("-----END PUBLIC KEY-----","") return binascii.hexlify(base64.b64decode(data)) def show_asn1(string, indent=0): while not string.eof(): tag = string.peek() if tag.typ == asn1.Types.Primitive: tag, value = string.read() print(' ' * indent,end='') print('[{}] {}: {}'.format(class_id_to_string(tag.cls), tag_id_to_string(tag.nr),value_to_string(tag.nr, value))) if (tag.nr==4): private_key=binascii.hexlify(value) print(' ' * indent,end='') print("Private key: ",private_key.decode()) if (tag.nr==3): res=binascii.hexlify(value).decode() length=len(res) if (res.__contains__('10001')): # RSA rtn=res[1:].find("02") print (res[rtn+3:rtn+5]) byte = int(res[rtn+3:rtn+5],16)-1 rtn=res[1:].find("00") N=res[rtn+3:rtn+3+(byte)*2] e=res[length-5:] print(' ' * indent,end='') print(f"RSA Modulus ({len(N)*4}) bits: {N}") print(f"RSA e: {e}") else : # ECC public_key_x=res[4:length/2] public_key_y=res[length/2:] print(' ' * indent,end='') print(f"Public key ({public_key_x}, {public_key_y})") elif tag.typ == asn1.Types.Constructed: print(' ' * indent,end='') print('[{}] {}'.format(class_id_to_string(tag.cls), tag_id_to_string(tag.nr))) string.enter() show_asn1(string, indent + 2) string.leave() if (der.__contains__("BEGIN")): print("Found PEM") der=read_pem(der) print (f"PEM: {der}\n") else: print (f"DER: {der}\n") st=binascii.unhexlify(der) decoder = asn1.Decoder() decoder.start(st) show_asn1(decoder) print() if (len(der)<200): make_pem(st)
and pem.py:
# based on code at https://github.com/andrivet/python-asn1 import base64 import asn1 import binascii def read_pem(data): """Read PEM formatted input.""" data = data.replace("-----BEGIN PUBLIC KEY-----","") data = data.replace("-----END PUBLIC KEY-----","") data = data.replace("\n","") data = data.replace("","") return binascii.hexlify(base64.b64decode(data)) tag_id_to_string_map = { asn1.Numbers.Boolean: "BOOLEAN", asn1.Numbers.Integer: "INTEGER (02)", asn1.Numbers.BitString: "BIT STRING", asn1.Numbers.OctetString: "OCTET STRING", asn1.Numbers.Null: "NULL", asn1.Numbers.ObjectIdentifier: "OBJECT (06)", asn1.Numbers.PrintableString: "PRINTABLESTRING", asn1.Numbers.IA5String: "IA5STRING", asn1.Numbers.UTCTime: "UTCTIME", asn1.Numbers.Enumerated: "ENUMERATED", asn1.Numbers.Sequence: "SEQUENCE (30)", asn1.Numbers.Set: "SET" } class_id_to_string_map = { asn1.Classes.Universal: "U", asn1.Classes.Application: "A", asn1.Classes.Context: "C", asn1.Classes.Private: "P" } object_id_to_string_map = { "1.2.840.113549.1.1.1": "RSA Encryption", "1.2.840.10040.4.1": "DSA", "1.2.840.10046.2.1": "Diffie-Hellman", "1.2.840.10045.2.1": "ECC", "1.2.840.10045.3.1.1": "secp192r1", "1.3.132.0.33": "secp224r1", "1.2.840.10045.3.1.7": "secp256r1", "1.3.132.0.34": "secp384r1", "1.3.132.0.35": "secp521r1", "1.3.36.3.3.2.8.1.1.1": "brainpoolP160r1", "1.3.36.3.3.2.8.1.1.3": "brainpoolP192r1", "1.3.36.3.3.2.8.1.1.5": "brainpoolP224r1", "1.3.36.3.3.2.8.1.1.7": "brainpoolP256r1", "1.3.36.3.3.2.8.1.1.9": "brainpoolP320r1", "1.3.36.3.3.2.8.1.1.11": "brainpoolP384r1", "1.3.101.112": "Ed25519", "1.3.101.113": "Ed448", "1.3.6.1.5.5.7.1.1": "authorityInfoAccess", "2.5.4.3": "commonName", "2.5.4.4": "surname", "2.5.4.5": "serialNumber", "2.5.4.6": "countryName", "2.5.4.7": "localityName", "2.5.4.8": "stateOrProvinceName", "2.5.4.9": "streetAddress", "2.5.4.10": "organizationName", "2.5.4.11": "organizationalUnitName", "2.5.4.12": "title", "2.5.4.13": "description", "2.5.4.42": "givenName", "1.2.840.113549.1.9.1": "emailAddress", "2.5.29.14": "X509v3 Subject Key Identifier", "2.5.29.15": "X509v3 Key Usage", "2.5.29.16": "X509v3 Private Key Usage Period", "2.5.29.17": "X509v3 Subject Alternative Name", "2.5.29.18": "X509v3 Issuer Alternative Name", "2.5.29.19": "X509v3 Basic Constraints", "2.5.29.30": "X509v3 Name Constraints", "2.5.29.31": "X509v3 CRL Distribution Points", "2.5.29.32": "X509v3 Certificate Policies Extension", "2.5.29.33": "X509v3 Policy Mappings", "2.5.29.35": "X509v3 Authority Key Identifier", "2.5.29.36": "X509v3 Policy Constraints", "2.5.29.37": "X509v3 Extended Key Usage" } def tag_id_to_string(identifier): """Return a string representation of a ASN.1 id.""" if identifier in tag_id_to_string_map: return tag_id_to_string_map[identifier] return '{:#02x}'.format(identifier) def class_id_to_string(identifier): """Return a string representation of an ASN.1 class.""" if identifier in class_id_to_string_map: return class_id_to_string_map[identifier] raise ValueError('Illegal class: {:#02x}'.format(identifier)) def object_identifier_to_string(identifier): if identifier in object_id_to_string_map: return object_id_to_string_map[identifier] return identifier def value_to_string(tag_number, value): if tag_number == asn1.Numbers.ObjectIdentifier: return object_identifier_to_string(value) elif isinstance(value, bytes): return '0x' + str(binascii.hexlify(value).upper()) elif isinstance(value, str): return value else: return repr(value)
For Example 1, we have secp256r1 public key and which is a 512-bit bit value:
DER: 3059301306072a8648ce3d020106082a8648ce3d030107034200042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e [U] SEQUENCE (30) [U] SEQUENCE (30) [U] OBJECT (06): 1.2.840.10045.2.1 - ECC [U] OBJECT (06): 1.2.840.10045.3.1.7 - secp256r1 [U] BIT STRING (03): 0xb'00042927B10512BAE3EDDCFE467828128BAD2903269919F7086069C8C4DF6C732838C7787964EAAC00E5921FB1498A60F4606766B3D9685001558D1A974E7341513E' Public key (2927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c73, 2838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e) -----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKSexBRK64+3c/kZ4KBKLrSkDJpkZ9whgacjE32xzKDjHeHlk6qwA5ZIfsUmKYPRgZ2az2WhQAVWNGpdOc0FRPg== -----END PUBLIC KEY-----
For Example 2, we have secp256k1 public key and which is a 512-bit bit value (x,y):
DER: 3056301006072a8648ce3d020106052b8104000a03420004b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee20a6ff0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9 [U] SEQUENCE (30) [U] SEQUENCE (30) [U] OBJECT (06): 1.2.840.10045.2.1 - ECC [U] OBJECT (06): 1.3.132.0.10 - secp256k1 [U] BIT STRING (03): 0xb'0004B838FF44E5BC177BF21189D0766082FC9D843226887FC9760371100B7EE20A6FF0C9D75BFBA7B31A6BCA1974496EEB56DE357071955D83C4B1BADAA0B21832E9' Public key (b838ff44e5bc177bf21189d0766082fc9d843226887fc9760371100b7ee2, 0a6ff0c9d75bfba7b31a6bca1974496eeb56de357071955d83c4b1badaa0b21832e9) -----BEGIN PUBLIC KEY----- MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEuDj/ROW8F3vyEYnQdmCC/J2EMiaIf8l2A3EQC37iCm/wyddb+6ezGmvKGXRJbutW3jVwcZVdg8Sxutqgshgy6Q== -----END PUBLIC KEY-----
For Example 4, we have an RSA public key:
DER: 305c300d06092a864886f70d0101010500034b003048024100a79850deede08e51270555ac9ea15623e22f902058fcdb87383cca46ca886ad6f95f6dcb7ed34198eb2ce07bc7459d1f4ebcce43c87147ebd263a67abaa8b3390203010001 [U] SEQUENCE (30) [U] SEQUENCE (30) [U] OBJECT (06): 1.2.840.113549.1.1.1 - RSA Encryption [U] NULL: None [U] BIT STRING (03): 0xb'003048024100A79850DEEDE08E51270555AC9EA15623E22F902058FCDB87383CCA46CA886AD6F95F6DCB7ED34198EB2CE07BC7459D1F4EBCCE43C87147EBD263A67ABAA8B3390203010001' 41 RSA Modulus (512) bits: a79850deede08e51270555ac9ea15623e22f902058fcdb87383cca46ca886ad6f95f6dcb7ed34198eb2ce07bc7459d1f4ebcce43c87147ebd263a67abaa8b339 RSA e: 10001 -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKeYUN7t4I5RJwVVrJ6hViPiL5AgWPzbhzg8ykbKiGrW+V9ty37TQZjrLOB7x0WdH068zkPIcUfr0mOmerqoszkCAwEAAQ== -----END PUBLIC KEY-----
This gives N (modulus) and e (public exponent). Notice that the modulus has 512 bits. A sample run of Example 5 gives an RSA private key:
Found PEM PEM: b'3082013a020100024100a53c172810b45f94cb1edbd6a7eeffd5fa94b4c692d00bec0760bc53dff8b3034ed82f92debb553ae6fc0663ab90247e71af25a7643ad055cec78345b92c36c7020301000102403de24885efe3ae1c8b0a6ea97151d8ad6a610167919aabac6582fc65a96f7a937b40f06c5594f0fe1a74b957e731a021f9b214bfcb7fecfee328a9b041eb8d41022100da6a12118066136f8b1478dd78625bb80ed2ffa6b525a0cbc89058a37040faa7022100c1ab44c7fd1fcc554f4143072361f0bf064619b25fcc54064def8692da5006e102203bf114585d46a65adc6e97e5201ece512b30591d2565d845551bd857b27d02cd02201acc03dc581dca3c1397481af8be587d55f4e521553804784ad8559a84328681022100bd24bc374ab656a11b2d531ac4eaebb5dd013848c654268d453942a39248bc32' [U] SEQUENCE (30) [U] INTEGER (02): 0 [U] INTEGER (02): 8654044925554532549785054750314308338587763208855695716391605935869296328735820938047895742443318767123757127004920549562929832206295216761753944235718343 [U] INTEGER (02): 65537 [U] INTEGER (02): 3241123833830294359437785813303396526704558462568671915999083993712130222451686069963329018332802634933730669893008580993200063767388575293253251934948673 [U] INTEGER (02): 98791611483293881907807921914950834893394309084025636551681513591207199046311 [U] INTEGER (02): 87598985335085576001047380619649676724919664057557267509065539711387594393313 [U] INTEGER (02): 27112408626249656834976170461911679149069839070834568244175713008704284328653 [U] INTEGER (02): 12120597510086760199238562147473690717328707656345717713233842167063837312641 [U] INTEGER (02): 85552033895547751806483403098216120111515145503032877299863582631881410657330 -----BEGIN PUBLIC KEY----- MIIBOgIBAAJBAKU8FygQtF+Uyx7b1qfu/9X6lLTGktAL7AdgvFPf+LMDTtgvkt67VTrm/AZjq5AkfnGvJadkOtBVzseDRbksNscCAwEAAQJAPeJIhe/jrhyLCm6pcVHYrWphAWeRmqusZYL8ZalvepN7QPBsVZTw/hp0uVfnMaAh+bIUv8t/7P7jKKmwQeuNQQIhANpqEhGAZhNvixR43XhiW7gO0v+mtSWgy8iQWKNwQPqnAiEAwatEx/0fzFVPQUMHI2HwvwZGGbJfzFQGTe+GktpQBuECIDvxFFhdRqZa3G6X5SAezlErMFkdJWXYRVUb2FeyfQLNAiAazAPcWB3KPBOXSBr4vlh9VfTlIVU4BHhK2FWahDKGgQIhAL0kvDdKtlahGy1TGsTq67XdAThIxlQmjUU5QqOSSLwy -----END PUBLIC KEY-----
This gives version, N (modulus), e (public exponent), d (private exponent), p1 (prime 1), p2 (prime 2), ex1 (d mod (p-1)), ex2 ( d mod (q-1)), co (co-efficient). For an ECC private key we have a 256-bit private key and a 512-bit public key:
DER: 30740201010420b9aa5c28ef96d750e47f4ba44d5d6a7ac3ab6988d292e7819e362a4b0ac8e250a00706052b8104000aa144034200047fef8e21686370c7d343992f14b2d45a262cd6a5c75032736fcbb02f46a99edf0e1d114cdc93956cc75648bfd38fa832a82135d5c2ba634766a8753f6d88aae5 [U] SEQUENCE (30) [U] INTEGER (02): 1 [U] OCTET STRING: 0xb'B9AA5C28EF96D750E47F4BA44D5D6A7AC3AB6988D292E7819E362A4B0AC8E250' Private key: b9aa5c28ef96d750e47f4ba44d5d6a7ac3ab6988d292e7819e362a4b0ac8e250 [C] 0x0 [U] OBJECT (06): 1.3.132.0.10 - secp256k1 [C] BOOLEAN [U] BIT STRING (03): 0xb'00047FEF8E21686370C7D343992F14B2D45A262CD6A5C75032736FCBB02F46A99EDF0E1D114CDC93956CC75648BFD38FA832A82135D5C2BA634766A8753F6D88AAE5' Public key (7fef8e21686370c7d343992f14b2d45a262cd6a5c75032736fcbb02f46a9, 9edf0e1d114cdc93956cc75648bfd38fa832a82135d5c2ba634766a8753f6d88aae5)
References
[1] RFC 3279, Algorithms and Identifiers for the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile [here]
A list of object IDs:
Hashing: MD2 1.2.840.113549.2.2 MD5 1.2.840.113549.2.5 SHA-1 1.3.14.3.2.26 SHA-224 2.16.840.1.101.3.4.2.4 SHA-256 2.16.840.1.101.3.4.2.1 SHA-394 2.16.840.1.101.3.4.2.2 SHA-512 2.16.840.1.101.3.4.2.3 Public key: RSA Encryption 1.2.840.113549.1.1.1 DSA 1.2.840.10040.4.1 Diffie-Hellman (dhPublicNumber) 1.2.840.10046.2.1 ECC (ecPublicKey) 1.2.840.10045.2.1 md2WithRsaEncryption 1.2.840.113549.1.1.2 Signatures: md5WithRsaEncryption 1.2.840.113549.1.1.4 sha1WithRsaEncryption 1.2.840.113549.1.1.5 sha224WithRsaEncryption 1.2.840.113549.1.1.14 sha256WithRsaEncryption 1.2.840.113549.1.1.11 sha384WithRsaEncryption 1.2.840.113549.1.1.12 sha512WithRsaEncryption 1.2.840.113549.1.1.13 dsaWithSha1 1.2.840.10040.4.3 dsaWithSha224 2.16.840.1.101.3.4.3.1 dsaWithSha256 2.16.840.1.101.3.4.3.2 ecdsaWithSha1 1.2.840.10045.4.1 ecdsaWithSha224 1.2.840.10045.4.3.1 ecdsaWithSha256 1.2.840.10045.4.3.2 ecdsaWithSha384 1.2.840.10045.4.3.3 ecdsaWithSha512 1.2.840.10045.4.3.4 Password Base Encryption Algorithms: pbeWithMd2AndDesCbc 1.2.840.113549.1.5.1 pbeWithMd5AndDesCbc 1.2.840.113549.1.5.3 pbeWithSha1AndDesCbc 1.2.840.113549.1.5.10 pbeWithMd2AndRc2Cbc 1.2.840.113549.1.5.4 pbeWithMd5AndRc2Cbc 1.2.840.113549.1.5.6 pbeWithSha1AndRc2Cbc 1.2.840.113549.1.5.11 pbeWithSha1And40BitRc2Cbc 1.2.840.113549.1.12.1.6 pbeWithSha1And128BitRc2Cbc 1.2.840.113549.1.12.1.5 pbeWithSha1And40BitRc4 1.2.840.113549.1.12.1.2 pbeWithSha1And128BitRc4 1.2.840.113549.1.12.1.1 pbeWithSha1And3DesCbc 1.2.840.113549.1.12.1.3 Symmetric Encryption Algorithms: DES CBC 1.3.14.3.2.7 3DES CBC 1.2.840.113549.3.7 RC2 1.2.840.113549.3.2 ArcFour 1.2.840.113549.3.4 AES CBC 128 2.16.840.1.101.3.4.1.2 AES CBC 256 2.16.840.1.101.3.4.1.42 x.500 Distinguished Name Attributes: name 2.5.4.41 surname 2.5.4.4 given name 2.5.4.42 initials 2.5.4.43 generation qualifier 2.5.4.44 common name 2.5.4.3 locality name 2.5.4.7 state or province name 2.5.4.8 organization name 2.5.4.10 organizational unit name 2.5.4.11 title 2.5.4.12 dnQualifier 2.5.4.46 country name 2.5.4.6 email address 1.2.840.113549.1.9.1 domain component 0.9.2342.19200300.100.1.25 street address 2.5.4.9 postal code 2.5.4.17 mail 0.9.2342.19200300.100.1.3 serial number 2.5.4.5 ECC names: secp192r1 1.2.840.10045.3.1.1 secp224r1 1.3.132.0.33 secp256r1 1.2.840.10045.3.1.7 secp384r1 1.3.132.0.34 secp521r1 1.3.132.0.35 brainpoolP160r1 1.3.36.3.3.2.8.1.1.1 brainpoolP192r1 1.3.36.3.3.2.8.1.1.3 brainpoolP224r1 1.3.36.3.3.2.8.1.1.5 brainpoolP256r1 1.3.36.3.3.2.8.1.1.7 brainpoolP320r1 1.3.36.3.3.2.8.1.1.9 brainpoolP384r1 1.3.36.3.3.2.8.1.1.11 brainpoolP512r1 1.3.36.3.3.2.8.1.1.13