Question

I have a dummy x509 certificate with the following subject

Subject: C=.., ST=..., O=..., OU=..., CN=.../emailAddress=123asd@asd.ds

The method

certificate.getSubjectX500Principal().getName()

returns

1.2.840.113549.1.9.1=#160d313233617364406173642e6473,CN=...,OU=...,O=...,ST=...,C=...

I need to parse this DN to a readable string.

Using bouncycastle I can get the value corresponding to the 1.2.840.113549.1.9.1 key from the symbols map (it's E) but I don't know what to do with this #160d313233617364406173642e6473.

How can I parse this #160d313233617364406173642e6473 to a readable string?

Was it helpful?

Solution

import javax.xml.bind.DatatypeConverter;    

byte[] data = DatatypeConverter.parseHexBinary(yourHexString);    
ASN1InputStream s = new ASN1InputStream(new ByteArrayInputStream(data));
ASN1String str = (ASN1String) s.readObject();
System.out.println(str.getString());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top