Flutter Gcm加密方法:
password是秘钥,长度必须是32位字符串
static Future<String> encrypt(String cleartext,{password='12345678901234567890123456789012'}) async {
Uint8List plaintext = utf8.encode(cleartext);
Uint8List iv = AesGcm.with256bits().newNonce();
Uint8List passphrase = utf8.encode(password);
SecretKey secretKey = new SecretKey(passphrase);
SecretBox secretBox = await AesGcm.with256bits().encrypt(plaintext, nonce: iv, secretKey: secretKey);
String ivCiphertextMacB64 = base64.encode(secretBox.concatenation()); // Base64 encoding of: IV | ciphertext | MAC
return ivCiphertextMacB64;
}
Flutter Gcm解密还没研究,有空再更新解密方法。