When i'm trying to decrypt a string using Blowfish it gives me an exception ( encrypting is fine)
javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
When i move the decrypting part to the encrypting method , it works fine.
i'm in JDK 1.5 and using SunJCE
Attaching the code
public static String bfEncrypt(String input) throws Exception {
Provider sunjce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunjce);
SecretKey ky = readKey(keyFile, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, ky);
byte[] inpByte = input.getBytes("UTF8");
byte[] ciphertext = cipher.doFinal(inpByte);
String citxt = new String(ciphertext, "UTF8");
return citxt;
}
public static String bfDecrypt(String cipherTxt) throws Exception {
Provider sunjce = new com.sun.crypto.provider.SunJCE();
Security.addProvider(sunjce);
SecretKey ky = readKey(keyFile, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, ky);
byte[] inputByte = cipherTxt.getBytes("UTF8");
byte[] decryptedText = cipher.doFinal(inputByte);
String output = new String(decryptedText, "UTF8");
return output;
}
Thanks in advance