IllegalBlockSizeException:输入长度不是 16 字节的倍数 AES/ECB/NoPadding
IllegalBlockSizeException: Input length not multiple of 16 bytes AES/ECB/NoPadding
我有这个片段,不知道为什么我用这个片段得到不规则的结果。
线索:适用于少于 200 个字符的短字符串,但当字符串在 260 个字符及以上的范围内时,它会抛出 javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
.
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
byte[] key = "secret_key".getBytes(StandardCharsets.UTF_8);
SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] cipherText = cipher.doFinal(request.getBytes(StandardCharsets.UTF_8));
String encryptedText = Base64.encodeBase64String(cipherText);
我有这个片段,不知道为什么我用这个片段得到不规则的结果。
线索:适用于少于 200 个字符的短字符串,但当字符串在 260 个字符及以上的范围内时,它会抛出 javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes
.
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
byte[] key = "secret_key".getBytes(StandardCharsets.UTF_8);
SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] cipherText = cipher.doFinal(request.getBytes(StandardCharsets.UTF_8));
String encryptedText = Base64.encodeBase64String(cipherText);