I have encrypted in flutter using dart library encrypt. Below is the code sample:
import 'package:encrypt/encrypt.dart' as enc;
final key = enc.Key.fromUtf8('Thisisasamplekeythatamusinginmyc'); //32 chars
final iv = enc.IV.fromUtf8('thisismysampleiv');//16 chars
String encryptMyData(String text) {
final e = enc.Encrypter(enc.AES(key));
final encrypted_data = e.encrypt(text, iv: iv);
return encrypted_data.base64;
}
I am able to encrypt but the issue arises when I try to decrypt the code using this code in JavaScript, using Crypto-JS:
const cryptkey = CryptoJS.enc.Utf8.parse('Thisisasamplekeythatamusinginmyc');
const crypted = CryptoJS.enc.Base64.parse("fdsUYHdv/5PoJSoZGwWppw==");
var decrypt = CryptoJS.AES.decrypt({ciphertext: crypted}, cryptkey, {
iv: CryptoJS.enc.Hex.parse('thisismysampleiv'),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
console.log(decrypt.toString(CryptoJS.enc.Utf8));
The problem is that it always returns an empty string, even using the AES.js library.
I have looked at this answer but same issue exists.