crypter 0.1.1 crypter: ^0.1.1 copied to clipboard
Encrypt data, decrypt data, hash stuff and validate hashes (using encrypt package and crypto package)
import 'dart:typed_data';
import 'package:crypter/crypter.dart';
void main() {
/// Some data
var data = Uint8List.fromList(List.generate(256, (i) => i));
/// A key
var key = 'ksajog9243shd42l9ds42';
/// Hash the data (automatically generates salt that is included in the hash)
var hash = Crypter.hash(data);
/// Encrypt the data
var encrypted = Crypter.encrypt(data, key);
/// Decrypting with the wrong key
Crypter.decrypt(data, 'aslkdf');
/// Decrypting with the correct key
var decrypted = Crypter.decrypt(encrypted, key);
/// The hash should equal
assert(Crypter.checkHash(decrypted, hash));
/// Note that the manual hashing here is not needed for encryption/decryption since the encrypted also contains a hash of the original object
}