当我尝试将 a 转换hex string
为 a 时,byte array
我得到了这个异常:
Aug 15, 2013 10:17:32 PM Tester main
SEVERE: null
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.BlowfishCipher.engineDoFinal(BlowfishCipher.java:319)
at javax.crypto.Cipher.doFinal(Cipher.java:1978)
at Tester.main(Tester.java:21)
以下是尝试这样做的代码:
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
SecretKey secretKey = keyGenerator.generateKey();
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
String decryptSt = new String(cipher.doFinal(DatatypeConverter.parseHexBinary("f250d7a040859d66541e2ab4a83eb2225d4fff880f7d2506")));
System.out.println(decryptSt);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(Tester.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchPaddingException ex) {
Logger.getLogger(Tester.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvalidKeyException ex) {
Logger.getLogger(Tester.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalBlockSizeException ex) {
Logger.getLogger(Tester.class.getName()).log(Level.SEVERE, null, ex);
} catch (BadPaddingException ex) {
Logger.getLogger(Tester.class.getName()).log(Level.SEVERE, null, ex);
}
问题是什么 ?为什么我得到一个例外?