I am trying to have an encryption/decryption setup. The encryption mode is ECB using the AES algorithm. For encryption, I am using CryptoJS as part of my application. The following code is used to encrypt:
var keyHex = CryptoJS.enc.Utf8.parse(key); alert(keyHex + ":" + keyHex.toString().length); var cipherText = CryptoJS.enc.Base64.stringify(CryptoJS.AES.encrypt(inputString, keyHex, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding}).ciphertext); console.log("Encrypted: " + cipherText); For decryption, I am using the AESCipherService of Shiro to decrypt. I have the following code:
public static String decryptUsingShiro(String base64EncodedData, String key) { byte[] base64decoded = Base64.decodeBase64(base64EncodedData.getBytes()); AesCipherService decryptService = new AesCipherService(); decryptService.setMode(OperationMode.ECB); decryptService.setPaddingScheme(PaddingScheme.PKCS5); ByteSource decrypt = decryptService.decrypt(base64decoded, key.getBytes()); return new String(decrypt.getBytes()); } I get the following exception:
Caused by: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Anything wrong I am doing on the encryption side?