【问题标题】:Java Applet Windows-MY keystore PrivateKey getEncoded is nullJava Applet Windows-MY 密钥库 PrivateKey getEncoded 为空
【发布时间】: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


【解决方案1】:

MSCAPI 似乎不支持私钥导出。

首先Key.getEncoded() javadoc 指定:

以其主要编码格式返回密钥,如果此密钥不支持编码,则返回 null。

如果您查看source code of the Java crypto provider for MSCAPIgetEncoded() 方法实际上在所有情况下都返回null

【讨论】:

  • 不要对非代码文本使用代码格式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-21
  • 1970-01-01
  • 2017-05-25
  • 2011-05-10
  • 1970-01-01
  • 2013-05-03
相关资源
最近更新 更多