aes_crypt
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 (latest) 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 the pubspec.yaml of your project, add the following dependency:
dependencies:
...
aes_crypt: ^0.1.1
In your Dart code add the following import:
import 'dart:typed_data';
import 'package:aes_crypt/aes_crypt.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);
Future plans
- reducing the memory usage for large file processing
- asynchronous encrypting/decrypting
- support for streams
- support for key files
Support
Please file feature requests and bugs at the issue tracker
I would be grateful if you help me to correct grammar and syntactical errors
for this readme and library documentation.
Acknowledgments