我解密一個文件,但它沒有顯示解密的字符串。它也扔了javax.crypto.IllegalBlockSizeException
。爲什麼解密的字符串不能顯示?
這是我的代碼:當輸入數據不是塊大小(在AES的情況下16個字節)的倍數發生
File f=new File("C:/Users/User/Desktop/Test.txt");
int ch;
StringBuffer strContent = new StringBuffer("");
FileInputStream fin = null;
try {
fin = new FileInputStream(f);
while ((ch = fin.read()) != -1)
strContent.append((char) ch);
fin.close();
}
catch (Exception e) {
System.out.println(e);
}
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128);
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] original =cipher.doFinal(strContent.toString().getBytes());
String originalString = new String(original);
JOptionPane.showMessageDialog(null,originalString.toString());
你可以顯示錯誤嗎?沒有它,我們無法幫助。 – skiwi
當您在'String originalString = ...'行上設置斷點時,'original'包含了什麼? –
線程「main」中的異常javax.crypto.IllegalBlockSizeException – newlearner