gpt4 book ai didi

java - 使用 Java 和 SunMSCAPI 从 MS 证书存储中删除证书

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:52 25 4
gpt4 key购买 nike

我正在尝试从 Windows 的“受信任的根证书颁发机构”证书存储中删除证书。可以使用 SunMSCAPI 提供程序并根据 oracle's documentation 从 java 访问此存储。人们应该能够读取和写入“个人”存储和“受信任的根证书颁发机构”。至少这是我对这句话的解释

In addition, changes are reflected immediately when making modifications to the keystore, such as KeyStore.setKeyEntry(...), KeyStore.deleteEntry(...).

但是,当尝试删除条目时,我收到 java.security.KeyStoreException:访问被拒绝。

我的代码看起来像

final KeyStore msCertStore = KeyStore.getInstance("Windows-ROOT", "SunMSCAPI");
msCertStore.load(null, null);
if (msCertStore.containsAlias(mCertificateName))
{
getLogger().info("Removing certificate with alias '{}' from store '{}'", mCertificateName,
mCertificateStore.getStoreName());
msCertStore.deleteEntry(mCertificateName);
}

我得到的是

Exception in thread "main" java.security.KeyStoreException: Access is denied.

at sun.security.mscapi.KeyStore.removeCertificate(Native Method)
at sun.security.mscapi.KeyStore.engineDeleteEntry(KeyStore.java:542)
at sun.security.mscapi.KeyStore$ROOT.engineDeleteEntry(KeyStore.java:68)
at java.security.KeyStore.deleteEntry(Unknown Source)
at my.playground.DeleteCertificateCommand.execute(DeleteCertificateInstallerCommand.java:67)
...

用于执行代码的用户帐户是本地管理员,我可以在 Windows 的 certmgr.msc GUI 中手动从存储中删除证书。但使用上面的代码是行不通的。

从个人存储中删除证书Windows-MY 有效,但似乎与访问权限有关。但我需要什么权利?

顺便说一句:操作系统是 Windows Server 2008 RC2

最佳答案

http://www.oracle.com/technetwork/articles/javase/security-137537.html

// Note: When a security manager is installed, 
// the following call requires SecurityPermission
// "authProvider.SunMSCAPI".
ks.load(null, null);

关于java - 使用 Java 和 SunMSCAPI 从 MS 证书存储中删除证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29519186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com