lazyxchacha 1.1.0
lazyxchacha: ^1.1.0 copied to clipboard
Lazy XChaCha20-Poly1305 in Flutter base on cryptography
import 'package:convert/convert.dart';
import 'package:flutter/foundation.dart';
import 'package:lazyxchacha/keypair.dart';
import 'package:lazyxchacha/lazyxchacha.dart';
void main() async {
final lazyxchacha = LazyXChaCha.instance;
// Generate KeyPair
final clientKeyPair = await KeyPair.newKeyPair();
final serverKeyPair = await KeyPair.newKeyPair();
// Key Exchange
final clientSharedKey = await clientKeyPair.sharedKey(serverKeyPair.pk);
final serverSharedKey = await serverKeyPair.sharedKey(clientKeyPair.pk);
// Payload
const message = 'Hello lazyxchacha';
// Encrypt with client
final ciphertext = await lazyxchacha.encrypt(message, clientSharedKey);
// Decrypt with server
final plaintext = await lazyxchacha.decrypt(ciphertext, serverSharedKey);
// Output
debugPrint('Output: $plaintext');
// Raw bytes in / bytes out
final rawKey = hex.decode(clientSharedKey);
final rawPlaintext = Uint8List.fromList([0, 1, 2, 253, 254, 255]);
final rawCiphertext = await lazyxchacha.encryptRaw(rawPlaintext, rawKey);
final rawDecrypted = await lazyxchacha.decryptRaw(rawCiphertext, rawKey);
// Output
debugPrint('Raw output: $rawDecrypted');
}