Search code examples
sslssl-certificatex509asn.1der

Convert "emailAdress=<email-address>" found in Subject field of x.509 SSL certificate to hexadecimal


I have a 'Subject' of SSL x.509 certificate given as

Subject:    C=XX, ST=XX, L=XX, O=XX, OU=XX, [email protected], CN=trustasia.asia

and I want to covert this to binary stream as found in SSL certificate when it is sent on wire, I know definition Subject field is given in RFC-5280 in ASN.1 notation and DER encoding rules given in x.609 are to covert this field to binary representation, these two documents and with little help from code(which gave hexadecimal representations of OID such as id-at-countryName:2.5.4.6:{0x55, 0x04, 0x06}) i was able to covert all the RDNs(RelativeDistinguishedNames) to their binary representation, but I am stuck with emailAdress filds. I found its OID:1.2.840.113549.1.9.1 but don't know what it is hexadecimal representation.

Can you please guide me how can I covert this to binary representation.


Solution

  • I suspect that you are talking about OID encoding using ASN.1 Distinguished Encoding Rules (DER). I would suggest to check this article to get detailed information about OBJECT_IDENTIFIER encoding rules: OBJECT IDENTIFIER

    OID string value conversion to ASN.1 DER will result in:

    06 09 2A 86 48 86 F7 0D 01 09 01

    where, 0x06 -- is OBJECT_IDENTIFIER tag identifer, 0x09 -- encoded OID value length in bytes, the rest bytes (2A 86 48 86 F7 0D 01 09 01) represent OID binary form