aes256DecryptPlain method

Future<List<int>> aes256DecryptPlain({
  1. required FlutterAesGcm algorithm,
  2. required String rawKey,
  3. required int rawKeyLength,
  4. required String data,
  5. required int iteration,
  6. required int saltLength,
  7. required int ivLength,
})

Implementation

Future<List<int>> aes256DecryptPlain({
  required FlutterAesGcm algorithm,
  required String rawKey,
  required int rawKeyLength,
  required String data,
  required int iteration,
  required int saltLength,
  required int ivLength
}) async {
  final cText = base64.decode(data);
  final salt = cText.sublist(0, saltLength);
  final iv = cText.sublist(saltLength, saltLength + ivLength);
  final mac = cText.sublist(cText.length - saltLength);
  final text = cText.sublist(saltLength + ivLength, cText.length - saltLength);
  final key = await _deriveKey(rawKey, rawKeyLength, salt, iteration);

  final secretBox = SecretBox(text, nonce: iv, mac: Mac(mac));
  final cleartext = await algorithm.decrypt(
    secretBox,
    secretKey: key,
  );
  return cleartext;
}