Android 4.0以下版本的CA凭证安装不起作用

时间:2013-08-20 13:06:47

标签: android https

下面的代码在4.0及更高版本上成功安装了CA,但是它在4.0以下不起作用。任何机构都知道我做错了什么。

private void showCAInstallationDialog() {
    try {
        InputStream caInputStream = getResources()
                .openRawResource(R.raw.ca);
        if (caInputStream != null) {

            byte[] result;

            result = IOUtils.toByteArray(caInputStream);

            // The next line actually installs the certificate
            Intent intent = new Intent("android.credentials.INSTALL");
            intent.putExtra("name", getString(R.string.app_name) + " CA ");
            intent.putExtra("CERT", result);
            startActivityForResult(intent, CA_CERTIFICATE_ADDED);

        } else {
            Utility.logError(getSimpleName(),
                    "Error occurred while reading CA");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码 - (如果您仍需要答案)

java.security.cert.X509Certificate cert;
byte [] certArray = //conver this "cer" to PEM using PEMWriter (use bouncy Castle library "bcprov-jdk15-140.jar")

Intent intent = null;
intent = new Intent("android.credentials.SYSTEM_INSTALL");
intent.setClassName("com.android.settings","com.android.settings.CredentialInstaller");
intent.putExtra("CACERT_" + "nameOfCert" + "CA", certArray);
mContext.startActivityForResult(intent);

感谢。