Chacha20.poly1305Aead constructor

Chacha20.poly1305Aead()

Constructs ChaCha20-Poly1305-AEAD cipher ((RFC 7539, also known as AEAD_CHACHA20_POLY1305), which is a popular authenticating cipher based on ChaCha20.

If you use Flutter, you can enable cryptography_flutter. It can improve performance in many cases.

Things to know

Example

import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  final message = <int>[1,2,3];

  final algorithm = Chacha20.poly1305Aead();
  final secretKey = await algorithm.newSecretKey();

  // Encrypt
  final secretBox = await algorithm.encrypt(
    message,
    secretKey: secretKey,
  );
  print('Nonce: ${secretBox.nonce}')
  print('Ciphertext: ${secretBox.cipherText}')
  print('MAC: ${secretBox.mac.bytes}')

  // Decrypt
  final clearText = await algorithm.decrypt(
    secretBox,
    secretKey: secretKey,
  );
  print('Cleartext: $clearText');
}

Implementation

factory Chacha20.poly1305Aead() {
  return Cryptography.instance.chacha20Poly1305Aead();
}