搜索分类、插件与代码仓

插件详情v0.1.1

aes_crypt

用于以 AES Crypt 文件格式加密/解密文件、纯文本和二进制数据的 Dart 加密库。

近 30 天下载
100
喜欢数
87
Pub 分数
40

安装插件

flutter pub add aes_crypt

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于使用 AES Crypt 文件格式加密和解密数据的 Dart 库。它支持对明文、文件和二进制数据进行强加密保护。专为跨平台使用设计,使开发者能够在 Flutter 应用中实现安全的数据处理。该库遵循广受认可的 AES Crypt 标准,确保兼容性和可靠性。非常适合需要保护隐私的敏感信息存储或传输场景。

适合场景

  • 在存储前对用户数据进行加密
  • 保护配置文件
  • 保护应用程序中的敏感文本
  • 在设备之间传输加密文件
  • 安全存储凭据
  • 遵守数据保护法规

主要特点

  • AES加密在Crypt格式中
  • 支持文本、文件和二进制数据
  • 跨平台兼容性
  • 用于加密/解密的简单 API
  • 使用行业标准的AES算法
  • 开源且持续维护

适合对象

  • 需要安全本地数据存储的应用
  • 具有隐私保护功能的文件共享应用
  • 密码管理器
  • 安全的笔记应用
  • 处理敏感用户信息的应用程序
  • 开发人员优先考虑数据安全

使用建议

  • 需要谨慎管理密钥
  • 不适用于高性能批量加密
  • 依赖外部加密标准
  • 仅限 AES 加密格式
  • 无内置密钥派生(用户必须自行安全处理)
  • 最好与额外的身份验证层配合使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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:

// Overwrites the file if it exists.
crypt.setOverwriteMode(AesCryptOwMode.on);

// If the file exists, stops the operation and throws 'AesCryptException'
// exception with 'AesCryptExceptionType.destFileExists' type (see 
// example1.dart in 'example'  folder). This mode is set by default.
crypt.setOverwriteMode(AesCryptOwMode.warn);

// If the file exists, adds index '(1)' to its' name and tries to save. 
// If such file also exists, adds '(2)' to its name, then '(3)', etc. 
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:

// Encrypts the file srcfile.txt and saves encrypted file under original name 
// with '.aes' extention added (srcfile.txt.aes). You can specify relative or 
// direct path to it. To save the file into current directory specify it 
// either as './srcfile.txt' or as 'srcfile.txt'.
crypt.encryptFileSync('srcfile.txt');

// Encrypts the file srcfile.txt and saves encrypted file under 
// the name enc_file.txt.aes
crypt.encryptFileSync('srcfile.txt', 'enc_file.txt.aes');

// Decrypts the file srcfile.txt.aes and saves decrypted file under 
// the name srcfile.txt
crypt.decryptFileSync('srcfile.txt.aes');

// Decrypts the file srcfile.txt.aes and saves decrypted file under 
// the name dec_file.txt
crypt.decryptFileSync('srcfile.txt.aes', 'dec_file.txt');

Text <=> file encryption/decryption:

String decryptedText;

// Plain text to be encrypted
String srcText = 'some text';

// Encrypts the text as UTF8 string and saves it into 'mytext.txt.aes' file.
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes');
// Encrypts the text as UTF16 Big Endian string and saves it 
// into 'mytext.txt.aes' file.
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes', utf16: true);
// Encrypts the text as UTF16 Little Endian string and saves it 
// into 'mytext.txt.aes' file.
crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes', utf16: true, endian: Endian.little);
// Add 'bom: true' as an argument if you want to add byte order mark 
// at the beginning of the text string before the encryption. For example:
// crypt.encryptTextToFileSync(srcText, 'mytext.txt.aes', bom: true);

// Decrypts the file and interprets it based on byte order mark if it has one.
// Otherwise it will be interpreted as UTF8 text.
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes');
// Decrypts the file and interprets it based on byte order mark if it has one.
// Otherwise it will be interpreted as UTF16 Big Endian text.
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes', utf16: true);
// Decrypts the file and interprets it based on byte order mark if it has one.
// Otherwise it will be interpreted as UTF16 Little Endian text.
decryptedString = crypt.decryptTextFromFileSync('mytext.txt.aes', utf16: true, endian: Endian.little);

Binary data <=> file encryption/decryption:

// Binary data to be encrypted
Uint8List srcData = Uint8List.fromList([1,2,3,4,5]);

// Encrypts the data and saves it into mydata.bin.aes file.
crypt.encryptDataToFileSync(srcData, 'mydata.bin.aes');

// Decrypt the data from 'mydata.bin.aes' file
Uint8List decryptedData = crypt.decryptDataFromFileSync('mydata.bin.aes');

Binary data AES encryption/decryption:

// The encryption key. It should be 128, 192 or 256 bits long.
Uint8List key = Uint8List.fromList([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);

// The initialization vector used in advanced cipher modes. 
// It must be 128 bits long.
Uint8List iv = Uint8List.fromList([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);

// AES mode of operation. It can be one of the next values:
//    AesMode.ecb - ECB (Electronic Code Book)
//    AesMode.cbc - CBC (Cipher Block Chaining)
//    AesMode.cfb - CFB (Cipher Feedback)
//    AesMode.ofb - OFB (Output Feedback)
// By default the mode is AesMode.cbc
AesMode mode = AesMode.cbc; // Ok. I know it's meaningless here.

// Sets the encryption key and IV.
crypt.aesSetKeys(key, iv);
// Sets cipher mode
crypt.aesSetMode(mode);

// If you wish you can set the key, IV and cipher mode in one function.
//crypt.aesSetParams(key, iv, mode);

// The binary data to be encrypted
Uint8List srcData = Uint8List.fromList([1,2,3,4,5]);

// Encrypts the data. Padding scheme - null byte (0x00).
Uint8List encryptedData = crypt.aesEncrypt(srcData);
// Decrypts the data
Uint8List decryptedData = crypt.aesDecrypt(encryptedData);

SHA256 and HMAC-SHA256 computation:

// The source data
Uint8List srcData = Uint8List.fromList([1,2,3,4,5,6,7,8,9]);

// Computes SHA256 hash
Uint8List hash = crypt.sha256(srcData);

// Secret cryptographic key for HMAC
Uint8List key = Uint8List.fromList([1,2,3]);

// Computes HMAC-SHA256 code
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

所属分类

源码仓库

使用此插件的项目

暂无相关数据。