3

我从 xml 文件中提取了 x509certificate 数据

        <X509Data>
            <X509Certificate>
      MIIB7DCCAVmgAwIBAgIQPjHcBTL63bBLuJZ88RcrCjAJBgUrDgMCHQUAMBExDzANBgNVBAMT
      BnJvbWVvazAgFw0xMDAzMTUwMjI1MjZaGA8yMTEwMDIxOTAyMjUyNlowETEPMA0GA1UEAxMG
      cm9tZW9rMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAu/sBh13A27rR7gJpZsI6zCee
      TXNohQWlq2z6Zg8Oxzsy5JoVV....==
            </X509Certificate>
        </X509Data>

如何从这些数据中创建 Java X509Certificate?

我已经试过了

    CertificateFactory cf = CertificateFactory.getInstance(X_509);
    ByteArrayInputStream bais = new ByteArrayInputStream(certBytes);
    X509Certificate x509cert = (X509Certificate) cf.generateCertificate(bais);
    bais.close();

但是出现错误

java.security.cert.CertificateParsingException: invalid DER-encoded certificate data.

任何帮助表示赞赏。

4

1 回答 1

1

这些字节是 PEM。Java可以处理它,但如果将它包含在“-----BEGIN CERTIFICATE-----”和“-----END CERTIFICATE-----”之间

于 2012-10-27T00:54:22.783 回答