QinGang_interested/lib/tools/encrypt.dart

26 lines
667 B
Dart
Raw Permalink Normal View History

2025-12-12 09:11:30 +08:00
import 'package:dart_sm/dart_sm.dart';
import 'package:qhd_prevention/http/ApiService.dart';
import 'package:qhd_prevention/tools/tools.dart' hide C1C2C3;
class Encrypt {
static String? encrypt(String text) {
try {
final md5 = md5Hex(text);
// 尝试用 C1C2C3Hutool 常见顺序)
final raw = SM2.encrypt(md5, ApiService.publicKey);
final encrypted = ensureC1Has04(raw);
print('encrypted:$encrypted');
return encrypted;
} catch (e) {
return null;
// return false;
}
}
static String decrypt(String codeText) {
final dec = SM2.decrypt(codeText, ApiService.privateKey);
return dec;
}
}