I have this snippet, Not sure why I am getting irregular results with this snippet.
Clue: Works well with a short string of fewer than 200 characters but when the string is in the ranges of 260 characters and above, it throws a 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);