String keyStorePath = "2keystore.jks";
String keyStoreType = "JKS";
String keyStorePassword = "mypass";
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
InputStream ksis = ClassLoader.getSystemResourceAsStream(keyStorePath);
keyStore.load(ksis, keyStorePassword.toCharArray());
ksis.close();
// Above seems to work fine
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
// Above throws exception:
// UnrecoverableKeyException: Cannot recover key
然而,使用 keytool,我可以查看如下内容2keystore.jks
:
keytool -list -v -keystore 2keystore.jks | more
Enter keystore password: mypass
Keystore type: JKS
Keystore provider: SUN
Your keystore contains 3 entries
Alias name:
...
知道尝试将此密钥库加载到 中时可能出现什么问题KeyManagerFactory
吗?
谢谢