标签:style http java color io 代码
首先说明用Java自带的解析x509证书类,是不能解析sm2算法的证书,运行会抛出异常。
用开源库bouncycastle可以解析、具体代码
private byte[] getCSPK(byte[] csCert)
{
InputStream inStream = new ByteArrayInputStream(csCert);
ASN1Sequence seq = null;
ASN1InputStream aIn;
try
{
aIn = new ASN1InputStream(inStream);
seq = (ASN1Sequence)aIn.readObject();
X509CertificateStructure cert = new X509CertificateStructure(seq);
cert.getVersion();
ASN1Primitive publicKey = cert.getSubjectPublicKeyInfo().getPublicKey();
byte[] encodedPublicKey = publicKey.getEncoded();
byte[] eP = new byte[64];
System.arraycopy(encodedPublicKey, 5, eP, 0, eP.length);
return eP;
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
java 解析国密SM2算法证书,布布扣,bubuko.com
java 解析国密SM2算法证书
标签:style http java color io 代码
原文地址:http://blog.csdn.net/a956959099/article/details/37756353