使用tomcat,我有两个web应用程序,即app1和app2.我将app1以加密形式(使用下面的代码)发送到app2.然后在app2我解密了这个加密的网址.但是我在decryp方法的第50行低于例外.
"Getting javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher"
Run Code Online (Sandbox Code Playgroud)
虽然我尝试在app1解密(使用相同代码)加密的URL时进行调试,但它工作正常.但无法弄清楚在app2引起此异常的原因是什么?
这是代码
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class AESEncryptionDecryptionTest {
private static final String ALGORITHM = "AES";
private static final String myEncryptionKey = "ThisIsFoundation";
private static final String UNICODE_FORMAT = "UTF8";
public static String encrypt(String valueToEnc) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encValue = c.doFinal(valueToEnc.getBytes());
String encryptedValue = new …Run Code Online (Sandbox Code Playgroud)