我有以下密码(已加密)和密钥
密码= bbSOvqxMRpO004qYLD / REQ ==
key = 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)