如何以编程方式删除用户安装的证书? [英] How to delete user installed certificate programmatically?
问题描述
我已经编程安装了证书。
I had installed a certificate programmatically.
我可以手动将设置卸载 - >安全 - >可信凭证 - >用户 - >选择证书,然后单击删除按钮
我希望以编程方式删除的证书。
I want to remove the certificate programmatically.
下面是code,我试过,但没有奏效。
Here is the code that I tried but it didn't work.
javax.security.cert.X509Certificate x509 = javax.security.cert.X509Certificate.getInstance(caRootCertBytes);
KeyStore ks = KeyStore.getInstance("AndroidCAStore")
if (ks != null)
{
ks.load(null, null);
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements())
{
String alias = (String) aliases.nextElement();
java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) ks.getCertificate(alias);
String name = x509.getIssuerDN().getName();
if (cert.getIssuerDN().getName().contains(name))
{
ks. deleteEntry(alias)
}
}
}
参考为什么我选择了<一href="http://developer.android.com/reference/java/security/KeyStore.html#deleteEntry(java.lang.String)">deleteEntry
下面是我得到的错误日志
Here is the error log that I got
05-19 18:27:40.789: W/System.err(14588): java.lang.UnsupportedOperationException
05-19 18:27:40.792: W/System.err(14588): at com.android.org.conscrypt.TrustedCertificateKeyStoreSpi.engineDeleteEntry(TrustedCertificateKeyStoreSpi.java:82)
05-19 18:27:40.792: W/System.err(14588): at java.security.KeyStore.deleteEntry(KeyStore.java:410)
05-19 18:27:40.792: W/System.err(14588): at com.proj.test.MyActivity$4.onClick(MyActivity.java:336)
05-19 18:27:40.792: W/System.err(14588): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
05-19 18:27:40.792: W/System.err(14588): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 18:27:40.792: W/System.err(14588): at android.os.Looper.loop(Looper.java:135)
05-19 18:27:40.793: W/System.err(14588): at android.app.ActivityThread.main(ActivityThread.java:5254)
05-19 18:27:40.793: W/System.err(14588): at java.lang.reflect.Method.invoke(Native Method)
05-19 18:27:40.794: W/System.err(14588): at java.lang.reflect.Method.invoke(Method.java:372)
05-19 18:27:40.794: W/System.err(14588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
05-19 18:27:40.794: W/System.err(14588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
此问题在某种程度上与我的其他问题
This question is somewhat related to my other question
任何帮助是AP preciated!
Any help is appreciated !
推荐答案
看起来像实施的KeyStoreSpi接口只是不支持拆卸:
Looks like that implementation of the KeyStoreSpi interface just doesn't support removal:
@Override
public void engineDeleteEntry(String alias) {
throw new UnsupportedOperationException();
}
<一个href="https://android.googlesource.com/platform/external/conscrypt/+/master/src/platform/java/org/conscrypt/TrustedCertificateKeyStoreSpi.java#81">https://android.googlesource.com/platform/external/conscrypt/+/master/src/platform/java/org/conscrypt/TrustedCertificateKeyStoreSpi.java#81
这篇关于如何以编程方式删除用户安装的证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!