I want to AES encrypt data for the http requests in flutter. I have password and plaintext string which I want to encrypt. I am using flutter_string_encryption. I have achieved in iOS app but both the output differs.

final salt = await cryptor.generateSalt();
final generatedKey = await cryptor.generateKeyFromPassword(password, salt);
final String encrypted = await cryptor.encrypt(string, generatedKey);


Solution 1: AKushWarrior

Do you have any particular attachment to flutter_string_encryption? I wrote a custom package based off PointyCastle and written entirely in Dart which can solve AES for you.

https://pub.dev/packages/steel_crypt

It looks something like this implemented:

var fortunaKey = CryptKey().genFortuna(); //generate 32 byte key with Fortuna; you can also enter your own
var nonce = CryptKey().genDart(len: 12); //generate IV for AES with Dart Random.secure(); you can also enter your own
var aesEncrypter = AesCrypt(key: fortunaKey, padding: PaddingAES.pkcs7); //generate AES encrypter with key and PKCS7 padding
String encrypted = aesEncrypter.gcm.encrypt(inp: 'somedatahere', iv: nonce); //encrypt using GCM
String decrypted = aesEncrypter.gcm.decrypt(inp: encrypted, iv: nonce); //decrypt


Solution 2: ferox147

AKushWarrior's answer is right but if you don't want to use salt key it's ok, you can directly go with your encryption key

         encryptionKey ="qwertyuiop";//your encryption key
         var Encrypter = AesCrypt(encryptionKey, 'cbc', 'pkcs7'); 
         //using AES : CBC/ECB , encryptionKey and PKCS7 padding
         EncryptedData = Encrypter.encrypt("hello world");//your data instead of Hello world  
         DecryptedData = Encrypter.decrypt(EncryptedData);