Get privatekey from Keystore

青春壹個敷衍的年華 提交于 2019-12-08 12:05:27

问题


I have the following code to export certificates and keys from a keystore, that I created with keytool in Windows:

final KeyStore keystore = KeyUtil.loadKeystore("keystore.jks", "pass");  
UserInfo userinfo = new UserInfo(WSusername, WSpassword);  
X509Certificate clientcert = KeyUtil.getCertificate(CLIENT_KEY_ALIAS, keystore);  
X509Certificate servercert = KeyUtil.getCertificate(SERVER_KEY_ALIAS, keystore);  
PrivateKey clientprivate = KeyUtil.getPrivateKey(CLIENT_KEY_ALIAS, CLIENT_KEY_PASSWORD, keystore);  

Yet it fails at the last line with "unable to retrieve private key for signing" It can retrieve the clientcert, but when it tries clientprivate, it fails.


回答1:


My problem was that when I generated the keystore with keytool, it did not create the PrivateKey as a key entry. To fix this, I imported the .p12 keystore as the private key, which worked. My original code above then worked.



来源:https://stackoverflow.com/questions/209081/get-privatekey-from-keystore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!