encrypt abstract method

Future<SecretBox> encrypt(
  1. List<int> clearText, {
  2. List<int>? nonce,
  3. List<int> aad = const <int>[],
  4. Uint8List? possibleBuffer,
})

Encrypts the clearText and returns the SecretBox.

See Cipher.encrypt for more information.

Example

In this example, we use Chacha20.poly1305Aead:

import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  final cipher = Chacha20.poly1305Aead();
  final secretKey = await cipher.newSecretKey();
  final wand = await cipher.newCipherWandFromSecretKey(secretKey);

  // Encrypt
  final secretBox = await wand.encrypt([1,2,3]);

  print('Nonce: ${secretBox.nonce}');
  print('Cipher text: ${secretBox.cipherText}');
  print('MAC: ${secretBox.mac.bytes}');

  // Decrypt
  final clearText = await wand.decrypt(secretBox);
}

Implementation

Future<SecretBox> encrypt(
  List<int> clearText, {
  List<int>? nonce,
  List<int> aad = const <int>[],
  Uint8List? possibleBuffer,
});