Keystore was tampered with, or password was incorrect
843810Feb 20 2003 — edited Feb 20 2003I keep getting a java exception in my code - java.io.IOException: Keystore was tampered with, or password was incorrect
I am am storing a DESede SecretKey to disk from within servlet code - the part that gens the key and stores the key to disk works fine. The problem occurs with the servlet that reads a filename, loads the KeyStore and attempst to decrypt the encrypted file using the KeyStore. Here is the code I am using:
SecretKey key;
String keyPass = "mss";
char passwd[] = new char[keyPass.length()];
keyPass.getChars(0, keyPass.length(), passwd, 0);
// Create an 8-byte initialization vector
byte[] iv = new byte[] {
(byte) 0x8E, 0x12, 0x39, (byte) 0x9C,
0x07, 0x72, 0x6F, 0x5A
};
try{
//BufferedReader in = new BufferedReader(new FileReader(p_file));
FileInputStream in = new FileInputStream(p_file);
String keyStoreFileName = p_file + Constants.keyStoreSuffix;
// get the key from the keystore
KeyStore keyStore = KeyStore.getInstance("JCEKS");
FileInputStream m_file = new FileInputStream(keyStoreFileName);
keyStore.load(m_file, passwd); //initialize keyStore
key = (SecretKey)keyStore.getKey(Constants.keyStoreAlias,passwd);
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
// get a cipher, initialize, read in the file and de-crypt
Cipher c = Cipher.getInstance("DESede/CFB/PKCS5Padding");
c.init(Cipher.DECRYPT_MODE, key, paramSpec);
CipherInputStream m_cipherIn = new CipherInputStream(in,c);
InputStreamReader m_streamReader = new InputStreamReader(m_cipherIn);
BufferedReader m_bufReader = new BufferedReader( m_streamReader );
=====================================
Again, the error message I get in my logfile is: java.io.IOException: Keystore was tampered with, or password was incorrect. Any help would be greatly appreciated.
- Lana