flutter: error: type 'String' is not a subtype of type 'Encrypted' of 'encrypted'

1,047

Solution 1

The documentation said It all:

String decrypt(Encrypted encrypted, {IV iv})

You passed a String to Encrypted, and Encrypted is not a subtype of String.

Solution 2

var source = 'flutter app';
final decrypted = encrypter.decrypt64(source, iv: iv);
Share:
1,047
Parth Bhanderi
Author by

Parth Bhanderi

Updated on December 14, 2022

Comments

  • Parth Bhanderi
    Parth Bhanderi over 1 year

    I'm using : encrypt: ^3.2.0 I'm using AES encryption in flutter but when i decrypt my encrypted value it's give me this type of Error.

    flutter: error: type 'String' is not a subtype of type 'Encrypted' of '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;
      }
    
  • Parth Bhanderi
    Parth Bhanderi over 4 years
    Okay I'm passing Encrypted data and i got this Exception has occurred. FormatException (FormatException: Invalid character (at character 29) 73R634pZF8gPztaH7Qn7eu1U41BA== ^ )
  • Tokenyet
    Tokenyet over 4 years
    Sorry, this is an another question, and I have never used that plugin. This seems to be you passed the wrong Encrypted data, but I can't talk more about this.
  • Parth Bhanderi
    Parth Bhanderi over 4 years
    Okay Thanks Sir,
  • Tokenyet
    Tokenyet over 4 years
    You could mark as sloved, so let readers know this issue is sloved :)