lazyxchacha 1.1.0
lazyxchacha: ^1.1.0 copied to clipboard
Lazy XChaCha20-Poly1305 in Flutter base on cryptography
lazyxchacha #
Lazy XChaCha20-Poly1305 in Flutter base on cryptography
Algorithm details #
- Key exchange: X25519
- Encryption: XChaCha20
- Authentication: Poly1305
Usage #
- pubspec.yml
dependencies:
lazyxchacha: ^1.1.0
- Dart
final lazyxchacha = LazyXChaCha.instance
How to use #
- Generate KeyPair
final keyPair = await KeyPair.newKeyPair();
- Key Exchange & Shared Key
final clientKeyPair = await KeyPair.newKeyPair();
final serverKeyPair = await KeyPair.newKeyPair();
final clientSharedKey = await clientKeyPair.sharedKey(serverKeyPair.pk);
- Encrypt
final lazyXChaCha = LazyXChaCha.instance;
final sharedKey = await clientKeyPair.sharedKey(serverKeyPair.pk);
const plaintext = '{"message": "Hi"}';
final ciphertext = await lazyXChaCha.encrypt(plaintext, sharedKey);
- Decrypt
final lazyXChaCha = LazyXChaCha.instance;
final sharedKey = await clientKeyPair.sharedKey(serverKeyPair.pk);
const ciphertext = '1ec54672d8ef2cca351';
final plaintext = await lazyXChaCha.decrypt(ciphertext, sharedKey);
- Encrypt/Decrypt raw bytes
final lazyXChaCha = LazyXChaCha.instance;
final sharedKey = await clientKeyPair.sharedKey(serverKeyPair.pk);
final key = hex.decode(sharedKey); // or any 32-byte key
final plaintext = Uint8List.fromList([0, 1, 2, 253, 254, 255]);
final ciphertext = await lazyXChaCha.encryptRaw(plaintext, key); // Uint8List
final decrypted = await lazyXChaCha.decryptRaw(ciphertext, key); // Uint8List
