How to access certificate Extension (Information ) values?

泄露秘密 提交于 2019-12-06 02:29:41

Found the issue .
The returned value was DER Octet encoded value which needed to be decoded, here is the code i used to decode the value :

import org.bouncycastle.asn1.DERObject;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.ASN1InputStream;
.
.
.
.
byte[] UID =  cert.getExtensionValue("2.5.29.32");

DERObject derObject = toDERObject(UID);

if (derObject instanceof DEROctetString)
{
    DEROctetString derOctetString = (DEROctetString)derObject;
    derObject = toDERObject(derOctetString.getOctets());

}
System.out.println(derObject.toString());

And this is the function to convert DER to object.

Static public DERObject toDERObject(byte[] data) throws IOException
{
    ByteArrayInputStream inStream = new ByteArrayInputStream(data);
    ASN1InputStream DIS = new ASN1InputStream(inStream);
    return DIS.readObject();
} 

Hope this helps someone in need .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!