在java中使用blowfish时的javax.crypto.IllegalBlockSizeException

时间:2011-10-18 08:36:43

标签: java blowfish

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:doFinal方法抛出7个尾随字节。问题是什么? 最有趣的是 - 无论密钥字符串有多长,异常总是相同的--7个尾随字节。

1 个答案:

答案 0 :(得分:1)

无论如何,使用Gnucrypto库已经解决了这个问题