0

下面的代码在 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();
    }

}
4

1 回答 1

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);

谢谢。

于 2014-06-06T09:54:29.733 回答