encryptString method

Future<SecretBox> encryptString(
  1. String clearText, {
  2. required SecretKey secretKey,
})

Converts a string to bytes using utf8 codec and then calls encrypt.

Implementation

Future<SecretBox> encryptString(
  String clearText, {
  required SecretKey secretKey,
}) async {
  final bytes = utf8.encode(clearText);
  final secretBox = await encrypt(
    bytes,
    secretKey: secretKey,
    possibleBuffer: bytes,
  );

  // Overwrite `bytes` if it was not overwritten by the cipher.
  tryEraseBytes(bytes, unlessUsedIn: secretBox.cipherText);

  return secretBox;
}