证书安装异常

时间:2018-07-31 10:51:46

标签: java android x509certificate x509certificate2

我正在尝试使用以下代码安装证书。 .cer证书已成功安装,但无法安装.p12证书。

    try {
            InputStream stream = getAssets().open("mycer.p12");

            int size = stream.available();
            byte[] buffer = new byte[size];
            stream.read(buffer);
            stream.close();
            Intent intent = KeyChain.createInstallIntent();
            javax.security.cert.X509Certificate x509Certificate = javax.security.cert.X509Certificate.getInstance(buffer);
            intent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509Certificate.getEncoded());
            intent.putExtra(KeyChain.EXTRA_NAME, "testcer");
            startActivityForResult(intent, 1);
        } catch (Exception e) {
            // Handle exceptions here

虽然将.cer转换为javax.security.cert.X509Certificate成功,但是当我将.p12转换为javax.security.cert.X509Certificate时,出现以下异常。

           InvocationTargetException: javax.security.cert.CertificateException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: java.lang.RuntimeException: error:0c0000b9:ASN.1 encoding routines:OPENSSL_internal:WRONG_TAG

0 个答案:

没有答案