encryptSync method

SecretBox encryptSync(
  1. List<int> clearText, {
  2. required SecretKeyData secretKey,
  3. List<int>? nonce,
  4. List<int> aad = const <int>[],
  5. int keyStreamIndex = 0,
  6. Uint8List? possibleBuffer,
})

Implementation

SecretBox encryptSync(
  List<int> clearText, {
  required SecretKeyData secretKey,
  List<int>? nonce,
  List<int> aad = const <int>[],
  int keyStreamIndex = 0,
  Uint8List? possibleBuffer,
}) {
  nonce ??= newNonce();
  checkParameters(
    length: clearText.length,
    secretKey: secretKey,
    nonceLength: nonce.length,
    aadLength: aad.length,
    keyStreamIndex: keyStreamIndex,
  );
  final state = newState();
  state.initializeSync(
    isEncrypting: true,
    secretKey: secretKey,
    nonce: nonce,
    aad: aad,
    keyStreamIndex: keyStreamIndex,
  );
  final cipherText = state.convertSync(
    clearText,
    possibleBuffer: possibleBuffer,
  );
  return SecretBox(
    cipherText,
    nonce: nonce,
    mac: state.mac,
  );
}