将日语密码与KeyStore.load()一起使用会导致java.io.IOException:密钥库被篡改,或者密码不正确 [英] Using Japanese password with KeyStore.load() causes java.io.IOException: Keystore was tampered with, or password was incorrect

查看:335
本文介绍了将日语密码与KeyStore.load()一起使用会导致java.io.IOException:密钥库被篡改,或者密码不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法创建了密钥库:

I have created a Keystore using:

keytool -genkey -keystore myKeyStore-别名我自己

keytool -genkey -keystore myKeyStore -alias myself

,我提供的密码是日语,即"myPasswordは" 我正在使用以下代码加载密钥库文件

and the password i have given is in Japanese i.e. "myPasswordは" I am using the following code to load the keystore file

String KEYSTORE_FILE="C:/myKeyStore";//Path to the keystore file on disk.
PASSWORD="myPasswordは";//Password

KeyStore.getInstance("JKS").load(new FileInputStream(KEYSTORE_FILE),PASSWORD.toCharArray());

以上抛出以下异常: java.io.IOException:密钥库被篡改,或者密码不正确.

The above throws the following exception: java.io.IOException: Keystore was tampered with, or password was incorrect.

如果我使用英文密码创建密钥库,并在代码中使用相同的密码,那么它将正常工作.

If i create the keystore using an english password and use the same in code then it works fine.

最初,我使用以下命令创建了密钥库: keytool -genkey -keystore myKeyStore -alias mks 这将提示我输入我作为myPasswordは输入的密码,然后输入后续详细信息.在这种情况下,代码将生成上述异常.

Initially I created the keystore using the command: keytool -genkey -keystore myKeyStore -alias mks this will prompt me for the password which i enter as myPasswordは and then i enter the subsequent details. In this case, the code generates the above exception.

有趣的是,如果我使用以下命令创建密钥库: keytool -genkey -keystore myKeyStore-别名mks -storepass myPasswordは 那么我上面给出的代码可以正常工作.我正在使用linux.

The interesting thing is that if i create the keystore using : keytool -genkey -keystore myKeyStore -alias mks -storepass myPasswordは then the code that i have given above works fine. I am using linux.

推荐答案

此问题的根本原因是keytool实用程序不能正确解码在提示符下输入的非ASCII密码.

The root cause of this problem is that the keytool utility does not decode a non-ascii password entered at prompt correctly.

这是一个已知问题,可以在 http:中找到//bugs.sun.com/bugdatabase/view_bug.do;jsessionid=53546691146578386c644cb554976?bug_id=6433238

This is a known issue which can be found at http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=53546691146578386c644cb554976?bug_id=6433238

因此,解决方案是使用在提示时未输入密码的密码创建密钥库.这可以通过以下方式完成:

So, the solution is to create a keystore with a password not entered at prompt. This can be done in the following way:

keytool -genkey -keystore myKeyStore -alias myAlias -storepassすてきなパスワード

keytool -genkey -keystore myKeyStore -alias myAlias -storepass すてきなパスワード

这篇关于将日语密码与KeyStore.load()一起使用会导致java.io.IOException:密钥库被篡改,或者密码不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆