1
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 个尾随字节。

4

1 回答 1

1

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

于 2012-08-08T03:24:46.117 回答