Blowfish decryption issue
843810Nov 25 2004 — edited Nov 26 2004Hi,
This is the first time I have used encryption features in java and I am experiencing some issues.
I have been given a value which has been encrypted with blowfish and then base64 encoded.
I have also been given the key (a string) which was used for the blowfish encryption.
My task is to base64 decode the value, then decrypt it using blowfish.
I am testing this from within a JSP page and I have pasted the code below.
If I use "Blowfish/CBC/PKCS5Padding" for my algorithm, I get an error: "java.security.InvalidKeyException: Parameters missing"
If I use "Blowfish/ECB/PKCS5Padding" I get an error:
"javax.crypto.BadPaddingException: Given final block not properly padded"
I've had a look through some forums for answers but I am still stuck (even though the code I'm using seems the same).
Code:
--------------------------
String algorithm = "Blowfish/ECB/PKCS5Padding";
//String algorithm = "Blowfish/CBC/PKCS5Padding";
byte[] brdata = null;
String msg = "";
String originaldata = "base64encodedstring=";
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodeddata = decoder.decodeBuffer(originaldata);
String KeyData = "keystring";
byte[] KeyBytes = KeyData.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(KeyBytes,"Blowfish");
Cipher cipher = null;
cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
//brdata = decrypt(decodeddata,cipher);
brdata = cipher.doFinal(decodeddata);
msg = new String(brdata);
---------------------------------------------------------------------
Any help would be greatly appreciated
** Using java 2 SDK, SE v1.4.2_01 **