cryptography 1.0.0 cryptography: ^1.0.0 copied to clipboard
Cryptographic algorithms for digital signature, key agreement, encryption, message authentication, and hashing. X25519, ED25519, AES, Chacha20, and many more.
import 'package:cryptography/cryptography.dart';
Future<void> main() async {
// Generate a random 256-bit secret key
final secretKey = await chacha20.newSecretKey();
// Generate a random 96-bit nonce.
final nonce = chacha20.newNonce();
// Encrypt
final clearText = [1, 2, 3];
final cipherText = await chacha20Poly1305Aead.encrypt(
clearText,
secretKey: secretKey,
nonce: nonce,
);
print('Bytes: ${chacha20Poly1305Aead.getDataInCipherText(cipherText)}');
print('MAC: ${chacha20Poly1305Aead.getMacInCipherText(cipherText)}');
}