Flutter数据加密插件thunder_encryption的使用
Flutter数据加密插件thunder_encryption的使用
Flutter Dart Thunder Encryption Decryption
本项目将可读字符串(明文)转换为不可读字符串(密文)并解密字符串。
安装
要安装thunder_encryption,运行以下命令:
dart pub add thunder_encryption
使用
// 测试普通字符串 [EN]
String plainEnString = "Abd Alftah Nedal AlShanti";
String cipherEnString = TextEncryption.textEncryption(plainEnString);
String encipherEnString = TextDecryption.textDecryption(cipherEnString);
// 测试符号
String plainSymbolString = "(=++*/$@!*)";
String cipherSymbolString = TextEncryption.textEncryption(plainSymbolString);
String encipherSymbolString = TextDecryption.textDecryption(cipherSymbolString);
// 测试普通字符串 [AR]
String plainArString = "عبد الفتاح نضال الشنطي";
String cipherArString = TextEncryption.textEncryption(plainArString);
String encipherArString = TextDecryption.textDecryption(cipherArString);
print("\n" + ("*" * 25) + " 测试EN字符串 " + ("*" * 25));
print("明文EN文本 : $plainEnString");
print("密文EN文本 : $cipherEnString");
print("解密EN文本 : $encipherEnString");
print("\n" + ("*" * 25) + " 测试符号字符串 " + ("*" * 25));
print("明文符号文本 : $plainSymbolString");
print("密文符号文本 : $cipherSymbolString");
print("解密符号文本 : $encipherSymbolString");
print("\n" + ("*" * 25) + " 测试AR字符串 " + ("*" * 25));
print("明文AR文本 : $plainArString");
print("密文AR文本 : $cipherArString");
print("解密AR文本 : $encipherArString");
贡献
欢迎通过提交问题、建议新功能或提交拉取请求来贡献此项目,或者添加新的语言。
添加语言
- 前往lib/core/strings
- 创建一个用于新语言的新文件,例如[en_letters / ar_letters]
- 创建一个Map<String, int>用于字母,以便在加密时使用,并创建一个Map<int, String>用于解密时使用
class EnLetters {
// 创建ConstStrings的单例
static final EnLetters instance = EnLetters._internal();
factory EnLetters() => instance;
EnLetters._internal();
Map<String, int> enSmallLettersStringKey = {
"a": 0,
"b": 1,
};
Map<int, String> enSmallLettersIntKey = {
0: "a",
1: "b",
};
}
更多关于Flutter数据加密插件thunder_encryption的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复
更多关于Flutter数据加密插件thunder_encryption的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
thunder_encryption
是一个用于 Flutter 应用的数据加密插件,它提供了多种加密算法,可以帮助开发者轻松地在 Flutter 应用中实现数据加密和解密。以下是如何使用 thunder_encryption
插件的基本步骤:
1. 添加依赖
首先,在 pubspec.yaml
文件中添加 thunder_encryption
插件的依赖:
dependencies:
flutter:
sdk: flutter
thunder_encryption: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来安装依赖。
2. 导入插件
在你的 Dart 文件中导入 thunder_encryption
插件:
import 'package:thunder_encryption/thunder_encryption.dart';
3. 使用加密和解密功能
thunder_encryption
提供了多种加密算法,如 AES、RSA 等。以下是使用 AES 加密和解密的一个简单示例:
AES 加密
void encryptData() async {
final encryption = ThunderEncryption();
String plainText = "Hello, World!";
String key = "my32lengthsupersecretkey123456"; // 32字符长度的密钥
String iv = "my16lengthiv1234"; // 16字符长度的初始化向量
String encryptedText = await encryption.aesEncrypt(plainText, key, iv);
print("Encrypted Text: $encryptedText");
}
AES 解密
void decryptData() async {
final encryption = ThunderEncryption();
String encryptedText = "encrypted_text_here"; // 这里是加密后的文本
String key = "my32lengthsupersecretkey123456"; // 32字符长度的密钥
String iv = "my16lengthiv1234"; // 16字符长度的初始化向量
String decryptedText = await encryption.aesDecrypt(encryptedText, key, iv);
print("Decrypted Text: $decryptedText");
}
4. 其他加密算法
thunder_encryption
还支持其他加密算法,如 RSA、DES 等。你可以根据需要使用这些算法。例如,使用 RSA 加密:
RSA 加密
void rsaEncrypt() async {
final encryption = ThunderEncryption();
String plainText = "Hello, World!";
String publicKey = "your_public_key_here"; // 替换为你的公钥
String encryptedText = await encryption.rsaEncrypt(plainText, publicKey);
print("RSA Encrypted Text: $encryptedText");
}
RSA 解密
void rsaDecrypt() async {
final encryption = ThunderEncryption();
String encryptedText = "encrypted_text_here"; // 这里是加密后的文本
String privateKey = "your_private_key_here"; // 替换为你的私钥
String decryptedText = await encryption.rsaDecrypt(encryptedText, privateKey);
print("RSA Decrypted Text: $decryptedText");
}