扑朔迷离的AES加密

时间:2019-03-05 05:04:25

标签: encryption dart flutter aes password-encryption

我想用AES加密HTTP请求中的数据。我有要加密的密码和明文字符串。 我正在使用flutter_string_encryption。我已经在iOS应用程序中实现了,但是两者的输出有所不同。

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

2 个答案:

答案 0 :(得分:1)

您对flutter_string_encryption有任何特定的附件吗?我写了一个基于PointyCastle的自定义程序包,完全用Dart编写,可以为您解决AES。

https://pub.dev/packages/steel_crypt

看起来是这样实现的:

var fortunaKey = CryptKey().genFortuna(); //generate 32 byte key with Fortuna //you can also enter your own
var iv = CryptKey().genDart(16); //generate salt for AES with Dart Random.secure() //you can also enter your own
var aesEncrypter = AesCrypt(fortunaKey, 'cbc', 'pkcs7'); //generate AES CBC block encrypter with key and PKCS7 padding
String encrypted = aesEncrypter.encrypt('somedatahere', iv); //encrypt
String decrypted = aesEncrypter.decrypt(encrypted, iv); //decrypt

答案 1 :(得分:-1)

AKushWarrior的答案是正确的,但是如果您不想使用盐键也可以,则可以直接使用加密密钥

         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);