31 lines
841 B
Dart
31 lines
841 B
Dart
import 'package:encrypt/encrypt.dart';
|
|
|
|
class LoginUtil {
|
|
static final _keyString = '915eae87951a448c86c47796e44c1fcf';
|
|
static final _key = Key.fromUtf8(_keyString);
|
|
|
|
static final _encrypter = Encrypter(AES(_key, mode: AESMode.ecb, padding: 'PKCS7'));
|
|
|
|
/// AES 加密方法
|
|
static String encrypt(String plainText) {
|
|
if (plainText.isEmpty) {
|
|
return '';
|
|
}
|
|
final encrypted = _encrypter.encrypt(plainText);
|
|
|
|
return encrypted.base64;
|
|
}
|
|
|
|
/// AES 解密方法 (可选,如果需要解密的话)
|
|
static String decrypt(String encryptedText) {
|
|
if (encryptedText.isEmpty) {
|
|
return '';
|
|
}
|
|
final encrypted = Encrypted.fromBase64(encryptedText);
|
|
// 【核心修改】调用 decrypt 方法时不再需要传递 iv
|
|
final decrypted = _encrypter.decrypt(encrypted);
|
|
return decrypted;
|
|
}
|
|
}
|
|
|