I have a decipher method as following,
String decipher(String fkey, String lkey, String data, String hash) { final key = encypt.Key.fromUtf8(fkey + lkey); var encoded = utf8.encode(data); print([hash, hash.length]); // <-- prints [eeee690be8c240128000815052545661, 32] var iv = new Uint8List.fromList(utf8.encode(hash)); //utf8.encode(hash); print(iv); final encrypter = encypt.Encrypter(encypt.AES(key, mode: encypt.AESMode.cbc)); var encodedE = encypt.Encrypted.fromBase64(base64Encode(encoded.toList())); var decrypted = encrypter.decrypt(encodedE, iv: encypt.IV.fromBase64(base64Encode(iv.toList()))); return decrypted; } When I run this I get an error message as,
Invalid argument(s): Initialization vector must be the same length as block size
If I try to read the IV from a text file which contains the text "eeee690be8c240128000815052545661", then its start to work.
var iv = await File("./data/iv.txt").readAsBytes(); // This works Both Uint8List.fromList and readAsBytes() returns Uint8List so my problem is why it is not working with var iv = new Uint8List.fromList(utf8.encode(hash)); ?
没有评论:
发表评论