如何从Windows Key Store读取私钥?

时间:2017-08-26 19:42:41

标签: java rsa digital-signature keystore pki

是否可以从Windows密钥库中读取有效的私钥,如Windows中的Windows-MY,Windows-ROOT?我可以从其他存储中读取私钥,例如:pkcs12(.pfx,.p12),pkcs11,jks(.jks),jceks。我尝试过类似的东西但是对其他密钥库工作正常,但Windows-MY和Windows-ROOT返回无效且非空的私钥。

注意:此处,链中的私钥和公钥是有效的密钥对。

final char[] keyPass = "test1234".toCharArray();
X509Certificate[] chains=......;

KeyStore sourceKeyStore = KeyStore.getInstance("Windows-MY");
sourceKeyStore.load("null", keyPass);

Enumeration<String> sAliases = sourceKeyStore.aliases();
while (sAliases.hasMoreElements()) {
    String alias = sAliases.nextElement();
    Key privKey = sourceKeyStore.getKey("testName", keyPass); // privKey is not null here but misses some information

    sourceKeyStore.setKeyEntry("testName", privKey, keyPass, chains); //gives Key protection algorithm not found error
}

0 个答案:

没有答案