Encryption is an important topic when it comes to working with sensitive data. The first rule of the cryptography club is to never invent a cryptography system yourself.
The following are the best Flutter encryption packages:
encrypt
encrypt is a set of high-level APIs over PointyCastle for two-way cryptography. It supports AES with PKCS7 padding, RSA with PKCS1 and OAEP encoding, Salsa20, and SHA256 with RSA.
It provides a command line to create a key and iv with secure-random
.
final plainText = 'This is a secret message'; final key = Key.fromUtf8('my 32 length key................'); final iv = IV.fromLength(16); final encrypter = Encrypter(AES(key)); final encrypted = encrypter.encrypt(plainText, iv: iv); final decrypted = encrypter.decrypt(encrypted, iv: iv);
rsa_encrypt
This package allows you to quickly implement RSA encryption in a Flutter app. It covers everything from generating key pairs, encrypt and decrypting strings.
//Future to hold our KeyPair Future<crypto.AsymmetricKeyPair> futureKeyPair; //to store the KeyPair once we get data from our future crypto.AsymmetricKeyPair keyPair; Future<crypto.AsymmetricKeyPair<crypto.PublicKey, crypto.PrivateKey>> getKeyPair() { var helper = RsaKeyHelper(); return helper.computeRSAKeyPair(helper.getSecureRandom()); }
dbcrypt
dbcrypt is a port of jBCrypt to Dart. Password can be encrypted using BCrypt and verified. It hashes passwords using a version of Bruce Schneier’s Blowfish block cipher with modifications designed to raise the cost of offline password cracking.
//generate secure password var plainPassword = "[email protected]"; var hashedPassword = new DBCrypt().hashpw(plainPassword, new DBCrypt().gensalt()); //verify password var isCorrect = new DBCrypt().checkpw(plainPassword , hashedPassword );
simple_rsa
This library can encrypt and decrypt strings with a public and a private key.
let plainText = 'something'; final signedText = await signString(plainText, utf8.decode(base64.decode(privateKey))); final verified = await verifyString(plainText, signedText, utf8.decode(base64.decode(publicKey)));