-1
我有以下的密碼(這是已經被加密)和密鑰AES Decrypter的未正確填充
密碼= bbSOvqxMRpO004qYLD/REQ ==
鍵= VUzwYCbBBcEQxu6jvGrwnvAYCD2d7FpQ
以下代碼返回未正確填充 爲解密密碼,我不知道爲什麼。看了幾個例子後,我似乎在跟着他們。
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public abstract class AESDecrypter {
public static String decrypt(String encryptedString, String key) {
try {
SecretKeySpec keySpec = null;
Cipher decryptCipher = null;
//----
SecretKeySpec keySpec = null;
Cipher decryptCipher = null;
//----
keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
System.out.println(keySpec.toString());
decryptCipher = Cipher.getInstance("AES");
decryptCipher.init(Cipher.DECRYPT_MODE, keySpec);
System.out.println("End decrypt");
return new String(decryptCipher.doFinal(Base64.decodeBase64(encryptedString.getBytes("UTF-8"))), "UTF-8");
}
}
回報
Given final block not properly padded
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
at edu.uga.ovpr.decrypter.AESDecrypter.decrypt(AESDecrypter.java:35)
at edu.uga.ovpr.filetransferrer.FTPSConnection.<init>(FTPSConnection.java:44)
at edu.uga.ovpr.filetransferrer.FileTransferrer.getConnection(FileTransferrer.java:285)
at edu.uga.ovpr.filetransferrer.FileTransferrer.doTransfer(FileTransferrer.java:221)
at edu.uga.ovpr.filetransferrer.FileTransferrer.main(FileTransferrer.java:128)
那麼怎麼樣,你不只是吞下異常......我強烈懷疑拋出一個異常,但是你失去了所有的信息。無論如何,您應該很少捕獲「Exception」(更喜歡捕獲特定的異常),並且幾乎不會*僅僅在沒有記錄異常的情況下返回一個值。 ('new String(...)'部分*絕對*不會返回'null'。) –
好的。我已經刪除了try和catch塊。現在,我得到一個 鑑於最終塊未正確填充 javax.crypto.BadPaddingException:鑑於最終塊未正確填充 在com.sun.crypto.provider.SunJCE_f.b(DashoA13 * ..) 在COM .sun.crypto.provider.SunJCE_f.b(DashoA13 * ..) at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13 * ..) at javax.crypto.Cipher.doFinal(DashoA13 * ..) at edu.uga.ovpr.decrypter.AESDecrypter.decrypt(AESDecrypter.java:35) – Evilsithgirl