首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >密钥工具错误: java.io.IOException:密钥库密码不正确

密钥工具错误: java.io.IOException:密钥库密码不正确
EN

Stack Overflow用户
提问于 2017-06-30 00:13:34
回答 3查看 19.7K关注 0票数 1

为Tomcat创建了一个证书,试图将其安装到新的密钥库中,但遇到错误(编辑:使用-v选项运行它,现在正在获取更多信息):

代码语言:javascript
运行
复制
keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2015)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at sun.security.tools.keytool.Main.loadSourceKeyStore(Main.java:1894)
    at sun.security.tools.keytool.Main.doImportKeyStore(Main.java:1926)
    at sun.security.tools.keytool.Main.doCommands(Main.java:1021)
    at sun.security.tools.keytool.Main.run(Main.java:340)
    at sun.security.tools.keytool.Main.main(Main.java:333)
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe contents entry: java.io.IOException: getSecretKey failed: Password is not ASCII

不幸的是,这是正确的,密码短语有两个"®“。那么,考虑到我所做的(私钥具有非ASCII密码),从这里恢复会有多痛苦?:

代码语言:javascript
运行
复制
1: Create a passphrase file: vi .kp
2: Make CSR:
A: Generate a 2048 bit private key:
openssl genpkey -algorithm RSA -outform PEM -out mike.privateKey.pass.pem -pkeyopt rsa_keygen_bits:2048 -pass file:.kp
B: Make the CSR:
openssl req -new -sha256 -key mike.privateKey.pass.pem -out mike.ike.com.cert.csr
Note: CSR has different "challenge password" than in the passphrase file, if that matters
3: Submit CSR to Comodo
4: Get certificate file mike_ike_com.cer & Comodo trust chain files: COMODORSAOrganizationValidationSecureServerCA.crt, COMODORSAAddTrustCA.crt, AddTrustExternalCARoot.crt
5: Convert the Certificates:
A: Convert to PEM:
openssl x509 -inform DER -in COMODORSAOrganizationValidationSecureServerCA.crt -out COMODORSAOrganizationValidationSecureServerCA.pem -outform PEM
openssl x509 -inform DER -in COMODORSAAddTrustCA.crt -out COMODORSAAddTrustCA.pem -outform PEM
openssl x509 -inform DER -in AddTrustExternalCARoot.crt -out AddTrustExternalCARoot.pem -outform PEM
B: Concat into a single file:
cat COMODORSAOrganizationValidationSecureServerCA.pem COMODORSAAddTrustCA.pem AddTrustExternalCARoot.pem > Comodo.root.crt 
C: Use openssl to create a pkcs12 file:
openssl pkcs12 -export -in mike_ike_com.cer -inkey mike.privateKey.pass.pem -passin file:.kp -out mike_ike.p12 -name tomcat -caname root -chain -CAfile Comodo.root.crt 
Note: when it asks "Enter Export Password" I give it the pw from .kp
6: Use keytool to create the keystore file:
$JAVA_HOME/bin/keytool -importkeystore -deststorepass:file .kp -destkeypass:file .kp -destkeystore .keystore -srckeystore mike_ike.p12 -srcstoretype PKCS12 -srcstorepass:file .kp -alias tomcat

文件".keystore“不存在。我假设keytool会创建它。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-06-30 00:56:25

好了,现在我有了答案。

1:密码中包含非ASCII字符。openssl可以处理这个问题,而keypass不能。

2:创建了使用非ASCII密码的私钥后,我坚持使用它,所以我将该文件重命名为.kpkey,并使用纯ASCII密码创建了一个新的.kp文件

3:这需要更改为5:C:

代码语言:javascript
运行
复制
openssl pkcs12 -export -in mike_ike_com.cer -inkey mike.privateKey.pass.pem -passin file:.kpkey -out mike_ike.p12 -name tomcat -caname root -chain -CAfile Comodo.root.crt 

注意:当它要求“输入导出密码”时,我从.kp给它pw,而不是从.kpkey。唯一的变化是-passin file:.kpkey

其他一切都保持不变,并且工作正常。

票数 1
EN

Stack Overflow用户

发布于 2017-06-30 00:19:01

我已经把这个问题解决了。我使用我的密码' password‘在JDK中更新cacerts keystore,而cacerts keystore的默认密码是'changeit’。

票数 0
EN

Stack Overflow用户

发布于 2022-02-11 11:42:01

我想添加另一个可能的原因:

此错误消息可能具有误导性,因为当密钥库的格式不受支持时也会出现此错误消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44830270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档