Hello Friends,
I am using bouncycastle java api to read X509 certificate. I need to
read the values of otherName.
Below is the code snippet that I am using:
private static void getAlternativeName(byte[] extVal) throws
CertificateParsingException {
try {
byte[] extnValue =
DEROctetString.getInstance(ASN1Object.fromByteArray(extVal)).getOctets();
Enumeration it =
DERSequence.getInstance(ASN1Object.fromByteArray(extnValue)).getObjects();
while (it.hasMoreElements()) {
GeneralName genName =
GeneralName.getInstance(it.nextElement());
switch (genName.getTagNo()) {
case GeneralName.otherName :
DERObject derObj = genName.getName().getDERObject();
System.out.println("Name ->" + derObj.getClass().getName());
//Above line is giving org.bouncycastle.asn1.DERSequence class.
System.out.println("In Other Name -> " +
genName.getName().getDERObject().toString());
//Above line is printing [1.3.6.1.4.1.311.20.2.3, [0]
AB...@GMAIL.COM]
// AND [2.16.840.1.101.3.6.6,
[0]#d4081858210c2c224d15cda1685a010c090211a2840810d7fc]
break;
default :
throw new IOException("Bad tag number: " + genName.getTagNo());
}
}
} catch (Exception e) {
throw new CertificateParsingException(e.getMessage());
}
}
As commented above I want to read the value
AB...@GMAIL.COM.
I tried all possible ways but could not able to do it.
Can someone let me know how can I read the value as a string.
Thanks,
Dheeram