【发布时间】:2015-06-01 16:35:59
【问题描述】:
根据我对documentation 的理解,应该可以通过服务"Windows-MY" 访问Microsoft Windows KeyStore。
当我从 keyStore 加载 PrivateKey 时,我得到 null for privateKey.getEncoded()。
如何从 Windows 密钥库正确访问 PrivateKey?
尝试通过以下方式访问它:
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null);
PrivateKey privateKey = (PrivateKey) ks.getKey("myKeyAlias", null);
System.out.println("privateKey:" + privateKey));
System.out.println("getEncoded:" + privateKey.getEncoded());
我得到的输出:
privateKey:RSAPrivateKey [size=2048 bits, type=Exchange, container=myKeyAlias]
getEncoded:null
使用 JRE 1.8 并通过 Win7 和 8.1 测试
【问题讨论】:
-
嗯?假设您的小程序将在其上运行的每台计算机 (a) 都使用 Windows 并且 (b) 有一个名为“myKeyAlias”的 KeyStore 条目(或您将在那里替换的任何内容),这有点牵强。跨度>
-
是的,这些都是先决条件,小程序也知道用户密钥别名。
标签: java security applet certificate x509certificate