crypton 2.2.1 crypton: ^2.2.1 copied to clipboard
A simple Dart library for asymmetric encryption and digital signatures
Examples #
Encryption and Decryption #
RSAKeypair rsaKeypair = RSAKeypair.fromRandom();
String message = DateTime.now().millisecondsSinceEpoch.toRadixString(16);
String encrypted = rsaKeypair.publicKey.encrypt(message);
String decrypted = rsaKeypair.privateKey.decrypt(encrypted);
Signing and Verifying #
Using RSA
RSAKeypair rsaKeypair = RSAKeypair.fromRandom();
String message = DateTime.now().millisecondsSinceEpoch.toRadixString(16);
String signature = rsaKeypair.privateKey.createSHA256Signature(utf8.encode(message) as Uint8List);
bool verified = rsaKeypair.publicKey.verifySHA256Signature(message, signature);
Using EC
ECKeypair ecKeypair = ECKeypair.fromRandom();
String message = DateTime.now().millisecondsSinceEpoch.toRadixString(16);
String signature = ecKeypair.privateKey.createSHA256Signature(utf8.encode(message) as Uint8List);
bool verified = ecKeypair.publicKey.verifySHA256Signature(message, signature);