I have the following Java code for creating an AES-128 cipher, where key and iv are both based on the same passphrase.
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] keyBytes = new byte[16];
byte[] b = passphare.getBytes("UTF-8");
int len = b.length;
if (len > keyBytes.length) {
len = keyBytes.length;
}
System.arraycopy(b, 0, keyBytes, 0, len);
SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(keyBytes);
cipher.init(opmode, keySpec, ivSpec);
cipher.doFinal(textToEncrypt.getBytes("UTF-8"));
I have tried to use the same approach in Javascript using CryptoJS for generating the same cipher, but with no success. Can you please help me?
TypeError: encrypted.ciphertext is undefined