【问题标题】:keytool error: java.io.IOException: keystore password was incorrectkeytool 错误:java.io.IOException:密钥库密码不正确
【发布时间】:2017-12-03 10:59:45
【问题描述】:

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

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 密码),从中恢复会有多大的痛苦?:

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 会创建它

【问题讨论】:

  • 如果您使用-passin file:.kp 作为密码,您可能还想尝试提供该密码:-):现在您正在执行-srcstorepass:file .kp
  • 我不明白你的评论 :-(

标签: java tomcat certificate keystore keytool


【解决方案1】:

我想补充另一个可能的原因:

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

【讨论】:

    【解决方案2】:

    好的,我有一个答案。

    1: 我的密码中有一个非 ASCII 字符。 openssl 可以处理,keypass 不能。

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

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

    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 的密码,而不是来自 .kpkey 的密码。唯一的变化是-passin file:.kpkey

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

    【讨论】:

    • 对于它的价值,我只有字母数字字符,但我仍然得到错误。导出了一个只有字母字符且 keytool 工作的新的?!
    【解决方案3】:

    我已经解决了这个问题。我使用我的密码“密码”来更新 JDK 中的 cacerts 密钥库,而 cacerts 密钥库的默认密码是“changeit”

    【讨论】:

    • 我使用 openssl 创建了 cacerts 密钥库,当它要求输入导出密码时,我可以设置密码:该部分有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 2022-10-30
    • 2021-06-15
    • 2011-05-14
    • 1970-01-01
    相关资源
    最近更新 更多