encryptWithKey static method

String encryptWithKey(
  1. Uint8List encryptionKey,
  2. Uint8List hmacKey,
  3. String plainText
)

Encrypts the input text by using a 32 byte length key and 16 byte length initialization vector.

Implementation

static String encryptWithKey(
    Uint8List encryptionKey, Uint8List hmacKey, String plainText) {
  final iv = _generateIv(RNCryptorSettings.ivLength);
  final cipherText = _encryptCore(encryptionKey, iv, plainText)!;

  var data = BytesBuilder();
  data.add([RNCryptorSettings.version]);
  data.add([0]);
  data.add(iv);
  data.add(cipherText);

  final hmac = _generateHmac(data.toBytes(), hmacKey);
  data.add(hmac);

  return base64.encode(data.toBytes());
}