Question

String key = "my_own_key_which_should_be_quite_long";
byte[] keyData = key.getBytes();
SecretKeySpec myKey = new SecretKeySpec(keyData, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, myKey);
String input = "string to encrypt";
try {
    byte[] encrypted = cipher.doFinal(input.getBytes());
    System.out.println(new String(encrypted));
} catch (Exception ex) {
    ex.printStackTrace();
}

javax.crypto.IllegalBlockSizeException: 7 trailing bytes is thrown by the doFinal method. What is the problem? What's the most interesting - no matter how long the key string is the exception is always the same - 7 trailing bytes.

Was it helpful?

Solution

Anyway, using Gnucrypto library has solved this problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top