I have created a Keystore using:
keytool -genkey -keystore myKeyStore -alias myself
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());
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.
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.
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.
The root cause of this problem is that the keytool utility does not decode a non-ascii password entered at prompt correctly.
This is a known issue which can be found at https://bugs.java.com/bugdatabase/view_bug;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 すてきなパスワード