【发布时间】:2020-11-17 19:35:29
【问题描述】:
我有这个 sn-p,不知道为什么我用这个 sn-p 得到不规则的结果。
线索:适用于少于 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);
【问题讨论】:
标签: java encryption cryptography aes ecb