天天看點

關于解析SM2證書

解析SM2證書,一般證書也可

@SuppressWarnings("deprecation")
    public static 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);
                ASN1Integer aserialNumber= cert.getSerialNumber();// 序列号
                String serialNumber=aserialNumber.toString();
                X500Name name= cert.getSubject();// 使用者
                X500Name issuer= cert.getIssuer(); // 頒發者
                Time stime=  cert.getStartDate(); // 有效期
                Time etime=cert.getEndDate();// 到
                DERBitString d=cert.getSignature();
                AlgorithmIdentifier alg= cert.getSignatureAlgorithm();
                ASN1ObjectIdentifier identifier= alg.getObjectId();// 簽名算法

                SubjectPublicKeyInfo subjectPublicKeyInfo = cert.getSubjectPublicKeyInfo();

                DERBitString publicKeyData = subjectPublicKeyInfo.getPublicKeyData();
                byte[] publicKey = publicKeyData.getEncoded();
                byte[] encodedPublicKey = publicKey;// 公鑰
                byte[] eP = new byte[];
                System.arraycopy(encodedPublicKey, , eP, , eP.length);
                return eP;
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

           

需要jar包

下載下傳位址http://download.csdn.net/detail/qq_32221419/9767434