decryptAES static method
AES-256-GCM解密
Implementation
static String decryptAES({
required String encryptedData,
required String userKey,
}) {
final parts = encryptedData.split(':');
if (parts.length != 2) {
throw const FormatException('Invalid encrypted data format');
}
final iv = IV.fromBase64(parts[0]);
final encrypted = Encrypted.fromBase64(parts[1]);
final keyBytes = _ensureKeyLength(userKey);
final key = Key.fromBase64(keyBytes);
final encrypter = Encrypter(AES(key, mode: AESMode.gcm));
return encrypter.decrypt(encrypted, iv: iv);
}