gpt4 book ai didi

java - Windows-MY 中的某些证书​​私钥未检测到

转载 作者:行者123 更新时间:2023-12-01 04:58:47 25 4
gpt4 key购买 nike

使用 Windows 7、JDK 6(和 7)。

我正在尝试获取存储在 Windows MSCAPI key 存储中的个人证书及其基本属性(以便使用私钥进行签名)。然而,某些别名被识别为没有私钥(isKeyEntry == false),尽管它实际上有一个。

对于如何处理这个“功能”有什么建议吗?

带有证书(已撤销)和具有这种奇怪“属性”的私钥的 P12 文件可以从 http://download.upce.cz/terena-public.pfx 下载。密码是“密码”。

KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
ks.load(null, null);
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = (String) aliases.nextElement();
X509CertImpl certificate = (X509CertImpl)ks.getCertificate(alias);
System.out.println("Alias: " + alias);
System.out.println(" Subject: " + certificate.getSubjectDN());
System.out.println(" Issued By: " + certificate.getIssuerDN());
if (ks.isKeyEntry(alias)) {
System.out.println(" Has private key");
}
}

最佳答案

我将您的 pfx 文件导入到 Mozilla Thunderbird 中,并将其导出为 p12 文件。现在我可以通过MSCAPI看到它了。原始证书中一定有某些内容阻止 MSCAPI 查看私钥。

我比较了这些文件,发现在原始文件中使用了“ key 用法”部分。

原始 pfx:

Bag Attributes
localKeyID: 01 00 00 00
friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541
Microsoft CSP Name: Microsoft Software Key Storage Provider
Key Attributes
X509v3 Key Usage: 90

转换后的 p12:

Bag Attributes
friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541
localKeyID: 47 E4 D3 F0 75 48 9D 77 07 E9 51 A4 F1 B6 DF E9 40 80 26 7A
Key Attributes: <No Attributes>

这两个文件存在更多差异,但我不确定哪一个会导致不良行为。

关于java - Windows-MY 中的某些证书​​私钥未检测到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13652206/

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