You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB
Dart

import 'dart:convert';
import 'package:encrypt/encrypt.dart';
class EncryptUtil {
static const List<int> intList16 = [
3,
8,
7,
8,
3,
7,
8,
9,
1,
8,
6,
8,
2,
8,
7,
8
];
//aes加密
static String aesEncode0(String content) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted =
encrypter.encrypt(content, iv: IV.fromBase64(base64Encode(intList16)));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//aes加密
static String aesEncode(String content) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted =
encrypter.encrypt(content, iv: IV.fromBase64(base64Encode(intList16)));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//aes解密
static String aesDecode(String base64) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
return encrypter.decrypt64(base64,
iv: IV.fromBase64(base64Encode(intList16)));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
//aes解密-dynamic
static dynamic aesDecodeDynamic(dynamic base64) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
return encrypter.decrypt64(base64,
iv: IV.fromBase64(base64Encode(intList16)));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
}