JM:I have a dream,期待和你一起去实现!
原文及译文
JM
网友:匿名网友

        我有以下代码来导出证书和密钥从密钥库,我用Windows中的keytool创建:最终KeyStore keystore = KeyUtil.loadKeystore(“keystore.jks”,“pass”); UserInfo userinfo = new UserInfo(WSusername,WSpassword); X5...

推荐:想去Google查资料?(你懂的)想建站?想测试?想挂机?想折腾?想要高性价比的服务器?点我!!


从Keystore获取私钥(Get privatekey from Keystore)

我有以下代码来从密钥库中导出证书和密钥,这是我在Windows中使用keytool创建的:

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);  

然而,它在最后一行“无法检索私钥进行签名”失败它可以检索clientcert,但是当它尝试clientprivate时,它会失败。


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.


解决方案(由网友匿名网友提供)

我的问题是,当我使用keytool生成密钥库时,并没有将PrivateKey创建为密钥条目。 T解决这个问题,我导入了.p12密钥库作为私人密钥,它的工作。我上面的原始代码然后工作。


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


推荐:想去Google查资料?(你懂的)想建站?想测试?想挂机?想折腾?想要高性价比的服务器?点我!!


关于站长

JMJavaMethod的缩写,苦逼码农一个,一直想有番作为,奈何人老力衰,只能四处膜拜大佬以获得动力。已经从单机、局域网、互联网、混到了移动互联网,未来希望能在AI世界里继续混下去。这辈子有个终极目标:财务自由,心灵自由。

近期公告

一个人苦逼开发多日,网站终于正式上线,求关注!!! 一个人苦逼多日,终于正式上线,求关注!!!

找他  
猜你喜欢
想建站?想测试?
想挂机?想折腾?
想去Google查资料?(你懂的)
想要高性价比的服务器?
搬瓦工VPS - 性价最高的美国便宜VPS主机
友情链接

冀ICP备17016304号 版权所有 © JavaMethod.com All Rights Reserved,Theme by 拼图