I have been trying encrypt an array of bytes using AES in JavaScript but I am experiencing some troubles with that. This is my code in Java and I can't reach the same result in JavaScript. Can someone helping me? I've tryed using CriptoJs, Forge-Node, AES-js but none of the worked fine.
public static byte[] Cipher() throws Exception {
byte[] msgCifrada = null;
byte[] keyBytes = [85, -9, -79, -24, -80, 87, -3, 73, 87, -75, -120, 125, 90, -124, 109, -102];
byte[] dados = [-88, -93, 5, -78, -116, 36, -49, -11, 106, 111, 110, 97, 116, 104, 97, 115, 46, 115, 105, 108, 118, 97];
try {
SecretKey secretKey = new SecretKeySpec(keyBytes, "AES");
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, secretKey);
msgCifrada = c.doFinal(dados);
} catch (InvalidKeyException ike) {
throw new Exception("Chave simétrica inválida.");
} catch (Exception e) {
throw new Exception("Erro na cifragem da mensagem: "+ .getMessage());
}
return msgCifrada;
}
The result in Java is that ByteArray:
[-90, 91, 44, 29, -113, 116, -1, -29, 42, 47, 122, -117, -12, -12, -49, -94, 59, -50, 110, 115, 105, -21, 80, 93, -15, 13, 71, -108, 23, -80, 56, -96]
Thank you!