java 带有 BouncyCastleProvider 的 KeyStore:KeyStore 完整性检查失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13125609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:35:37  来源:igfitidea点击:

KeyStore with BouncyCastleProvider: KeyStore integrity check failed

javasslbouncycastlekeystore

提问by K. D.

I want to use a self-signed signature for ssl connections. I'm following thispost.

我想对 ssl 连接使用自签名。我正在关注这个帖子。

My problem: After creating the Keystore my integrity-check fails.

我的问题:创建密钥库后,我的完整性检查失败。

Keytool-Error: java.io.IOException: KeyStore integrity check failed.

I'm still searching but maybe someone can save me some time.

我仍在寻找,但也许有人可以为我节省一些时间。

回答by Eddie Fletcher

Make sure you are using the right password to open the keystore. I was having this error and turns out I was still using the password from the example code in trusted.load()

确保您使用正确的密码打开密钥库。我遇到了这个错误,结果我仍在使用示例代码中的密码trusted.load()

回答by Assaf Gamliel

I had the same problem where I tried to open a KeyStorefile I saved locally and 2 reasons comes to mind:

我在尝试打开KeyStore本地保存的文件时遇到了同样的问题,我想到了两个原因:

  • You are storing your KeyStoreand loading it with a different password.
  • Your KeyStorefile was damaged some how thus flagging the integrity check.
  • 您正在KeyStore使用不同的密码存储和加载它。
  • 您的KeyStore文件已损坏,因此标记了完整性检查。

I'd suggest you try to save and load another file with the same password (fixed) just to see if it will load normally.

我建议您尝试使用相同的密码(固定)保存并加载另一个文件,看看它是否能正常加载。

回答by Richard Corfield

I have found another corner case that can provoke this message.

我发现了另一个可以引发此消息的角落案例。

I exported a PKCS12 keystore with openssland then tried to import it into an existing keystore with keytool. I received the 'integrity check failed' error at this step despite the password being good when I listed the contents of the PKCS12 keystore.

我导出了一个 PKCS12 密钥库,openssl然后尝试将它导入到现有的密钥库中keytool。尽管在列出 PKCS12 密钥库的内容时密码正确,但我在这一步收到了“完整性检查失败”错误。

The problem turned out to be because I'd used a password exactly 50 characters long. Although this is accepted by openssl, I understand that this is the maximum size of the buffer used and that the last character of the password get overwritten by an 'end of string' character.

问题原来是因为我使用了正好 50 个字符长的密码。尽管这被 接受openssl,但我知道这是所用缓冲区的最大大小,并且密码的最后一个字符会被“字符串结尾”字符覆盖。

Exporting the PKCS12 keystore again with a password of only 49 characters long fixed my issue.

使用只有 49 个字符长的密码再次导出 PKCS12 密钥库解决了我的问题。

回答by Cobolt

Ensure your keystore file is properly closed using FileOutputStream.close()or it will be marked as having lost integrity

确保您的密钥库文件已正确关闭FileOutputStream.close(),否则将被标记为已丢失完整性