I'm still trying to decrypt a file encoded with a password-based (PBKDF2) Blowfish cipher. I'm bit further now but starting to run out of ideas. Here is what I have so far:
// 1. Given a password, build a password-based key and from that build a Blowfish key
PBEKeySpec kspec = new PBEKeySpec( pwd.toCharArray(), salt, iterationCount, keySize );
SecretKeyFactory kfact = SecretKeyFactory.getInstance( "PBKDF2WithHmacSHA1" );
SecretKey sKey = kfact.generateSecret( kspec );
byte[] keyBytes = sKey.getEncoded(); // Is this right?
Key bfKey = new SecretKeySpec( keyBytes, "Blowfish" );
// 2. Given Blowfish key and initialization vector, decrypt the cipherText into plainText
Cipher cipher = Cipher.getInstance("Blowfish/CFB/NoPadding");
IvParameterSpec iv = new IvParameterSpec( initVector );
cipher.init( Cipher.DECRYPT_MODE, bfKey, iv );
byte[] plainText = cipher.doFinal( cipherText );
In a full test bed, this compiles and runs just fine, except that it doesn't appear to decrypt the data as expected.
More specifically, when I use Cipher.ENCRYPT_MODE to encrypt something like "This-is-a-test" and then decrypt the result with the code above only the first 8 bytes of the result return to plain text, the rest are garbage ("This-is-XXXX...").
The simple test case, at least, should work perfectly but I'm still missing something crucial. The fact that the first 8 bytes decode fine but not the rest feels like a hint to me, but I'm just not getting what the issue might be as I used the same password, initialization vector, key-, and cipher-types in both directions (encode/decode).
Help?