更新时间:2023-12-06 17:19:10
找到了问题。
返回的值是需要解码的DER Octet编码值,这是我用来解码值的代码:
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());
这是将DER转换为对象的函数。
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 .