Generate X509Certificate from byte[]?

前端 未结 3 1868
庸人自扰
庸人自扰 2021-01-31 07:30

Is there a possibility to generate an java.security.cert.X509Certificate from an byte[]?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 07:57

    You can do something like:

    X509Certificate certificate = signature.getKeyInfo().getX509Datas().get(0).getX509Certificates().get(0);
    
    String lexicalXSDBase64Binary = certificate.getValue();
    byte[] decoded = DatatypeConverter.parseBase64Binary(lexicalXSDBase64Binary);
    
    
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(decoded));
    

提交回复
热议问题