aes_crypt
Note
This package is a null-safe fork of the aes_crypt package, providing the same powerful AES encryption functionality with full null safety support for modern Dart and Flutter applications.
Introduction
aes_crypt is a library for Dart and Flutter developers that uses 256-bit AES algorithm
to encrypt/decrypt files, plain text and binary data. It is fully compatible with the
AES Crypt file format.
It can be used to integrate AES Crypt functionality into your own Dart or Flutter applications.
All algorithms are implemented in pure Dart and work in all platforms.
aes_crypt writes and reads version 2 of the AES Crypt file specification. Backwards compatibility
with reading the version 1 is implemented but untested.
Output .aes files are fully compatible with any software using the AES Crypt standard file format.
This library is accompanied by clients and libraries for different operating systems
and programming languages.
For more information about AES Crypt and AES Crypt compatible
applications for other platforms, please visit AESCrypt's official website.
Features
- 256-bit AES encryption format.
- File-to-file encryption and decryption.
- Memory-to-file encryption, file-to-memory decryption.
- Password can be in Unicode (like "密碼 パスワード пароль كلمة السر").
- Support for asynchronous file system reading/writing.
- Encrypted files have .aes extension which clients on other operating systems recognize.
- Compatible software available for Windows, Linux, Mac OS, Android and iOS
(https://www.aescrypt.com/download/).
Usage
In your Dart code add the following import:
import 'dart:typed_data';
import 'package:aes_crypt_null_safe/aes_crypt_null_safe.dart';
Initialization:
var crypt = AesCrypt('my cool password');
or
var crypt = AesCrypt();
crypt.setPassword('my cool password');
Optionally you can set overwrite mode for the file write operations:
crypt.setOverwriteMode(AesCryptOwMode.on);
crypt.setOverwriteMode(AesCryptOwMode.warn);
crypt.setOverwriteMode(AesCryptOwMode.rename);
Notice: All functions having 'Sync' at the end of their names are synchronous.
If you need asynchronous ones, please just remove 'Sync' from the end of function name.
File encryption/decryption:
crypt.encryptFileSync('srcfile.txt');
crypt.encryptFileSync('srcfile.txt', 'enc_file.txt.aes');
crypt.decryptFileSync('srcfile.txt.aes');
crypt.decryptFileSync('srcfile.txt.aes', 'dec_file.txt');
Text <=> file encryption/decryption:
String decryptedText;
String srcText = 'some text';
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes');
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes', utf16: true);
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes', utf16: true, endian: Endian.little);
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes');
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes', utf16: true);
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes', utf16: true, endian: Endian.little);
Binary data <=> file encryption/decryption:
Uint8List srcData = Uint8List.fromList([1,2,3,4,5]);
crypt.encryptDataToFileSync(srcData, 'mydata.bin.aes');
Uint8List decryptedData = crypt.decryptDataFromFileSync('mydata.bin.aes');
Binary data AES encryption/decryption:
Uint8List key = Uint8List.fromList([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
Uint8List iv = Uint8List.fromList([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
AesMode mode = AesMode.cbc;
crypt.aesSetKeys(key, iv);
crypt.aesSetMode(mode);
Uint8List srcData = Uint8List.fromList([1,2,3,4,5]);
Uint8List encryptedData = crypt.aesEncrypt(srcData);
Uint8List decryptedData = crypt.aesDecrypt(encryptedData);
SHA256 and HMAC-SHA256 computation:
Uint8List srcData = Uint8List.fromList([1,2,3,4,5,6,7,8,9]);
Uint8List hash = crypt.sha256(srcData);
Uint8List key = Uint8List.fromList([1,2,3]);
Uint8List hmac = crypt.hmacSha256(key, srcData);
Acknowledgments