aes256EncryptPlain method

Future<List<int>> aes256EncryptPlain({
  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>> aes256EncryptPlain({
  required FlutterAesGcm algorithm,
  required String rawKey,
  required int rawKeyLength,
  required String data,
  required int iteration,
  required int saltLength,
  required int ivLength
}) async {
  final salt = randomBytes(saltLength);
  final iv = randomBytes(ivLength);
  final secretKey = await _deriveKey(rawKey, rawKeyLength, salt, iteration);
  final secretBox = await algorithm.encrypt(
    utf8.encode(data),
    secretKey: secretKey,
    nonce: iv,
  );
  final List<int> result = salt + secretBox.nonce + secretBox.cipherText + secretBox.mac.bytes;
  return result;
}