Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Encryption flatter中的AES加密_Encryption_Dart_Flutter_Aes_Password Encryption - Fatal编程技术网

Encryption flatter中的AES加密

Encryption flatter中的AES加密,encryption,dart,flutter,aes,password-encryption,Encryption,Dart,Flutter,Aes,Password Encryption,我想在flatter中对http请求的数据进行AES加密。我有密码和明文字符串,我想加密。 我使用的是颤振字符串加密。我已在iOS应用程序中实现,但两种输出都不同 final salt = await cryptor.generateSalt(); final generatedKey = await cryptor.generateKeyFromPassword(password, salt); final String encrypted = await cryptor.encrypt(st

我想在flatter中对http请求的数据进行AES加密。我有密码和明文字符串,我想加密。 我使用的是颤振字符串加密。我已在iOS应用程序中实现,但两种输出都不同

final salt = await cryptor.generateSalt();
final generatedKey = await cryptor.generateKeyFromPassword(password, salt);
final String encrypted = await cryptor.encrypt(string, generatedKey);
         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); 

您是否有任何特定的颤振字符串加密附件?我基于PointyCastle编写了一个定制包,完全用Dart编写,可以为您解决AES问题

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

         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); 
它看起来像这样:

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

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

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

如果加密网络呼叫是目标。我建议使用TLS(HTTPS)来解决这个问题。您还必须在应用程序中锁定Cert/PubKey,以使其完全可靠。实际上,要求是对请求中的数据进行加密。但是比较加密文本是不同的。我认为这是因为final salt=wait cryptor.generateSalt();salt是随机生成的。是的,应该知道salt在两端都会加密/解密。如果无法获得加密的数据,您能为相同的数据提供一些来源吗?这是非常不安全的。如果多次使用同一密钥加密,则需要使用IV。