我正在使用:encrypt: ^3.2.0 我在扑朔迷离中使用AES加密,但是当我解密自己的加密值时,就会遇到这种错误。
flutter:错误:类型'String'不是'encrypted'的'Encrypted'类型的子类型
Future<String> getEncryption(String text) async {
String enc = '';
final SharedPreferences strFamilyPass =
await SharedPreferences.getInstance();
strFamilyPass.getString('family');
final String keys = await getKEY();
final dynamic key = Key.fromUtf8(keys);
final dynamic iv = IV.fromLength(16);
final dynamic encrypter = Encrypter(AES(key));
final String salt = await getSalt();
enc = '$salt${encrypter.encrypt(text, iv: iv).base64}';
print('encryption $enc');
return enc;
}
Future<String> getDecryption(String text) async {
String dec = '';
final String keys = await getKEY();
final dynamic key = Key.fromUtf8(keys);
final dynamic iv = IV.fromLength(16);
final encrypter = Encrypter(AES(key));
final String salt = await getSalt();
dec = '$salt${encrypter.decrypt(text, iv: iv)}';// it give's me error right here
print('decy $dec');
return dec;
}
答案 0 :(得分:2)
documentation全部说明:
String decrypt(Encrypted encrypted, {IV iv})
您将String
传递给Encrypted
,并且Encrypted不是String
的子类型。
答案 1 :(得分:1)
var source = 'flutter app';
final decrypted = encrypter.decrypt64(source, iv: iv);