flutter: error: type 'String' is not a subtype of type 'Encrypted' of 'encrypted'
flutter: error: type 'String' is not a subtype of type 'Encrypted' of 'encrypted'
我正在使用:encrypt: ^3.2.0
我在 flutter 中使用 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;
}
documentation 说了这一切:
String decrypt(Encrypted encrypted, {IV iv})
您将 String
传递给 Encrypted
,并且 Encrypted 不是 String
的子类型。
var source = 'flutter app';
final decrypted = encrypter.decrypt64(source, iv: iv);
我正在使用:encrypt: ^3.2.0 我在 flutter 中使用 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;
}
documentation 说了这一切:
String decrypt(Encrypted encrypted, {IV iv})
您将 String
传递给 Encrypted
,并且 Encrypted 不是 String
的子类型。
var source = 'flutter app';
final decrypted = encrypter.decrypt64(source, iv: iv);