QinGang_interested/lib/tools/encrypt.dart

26 lines
667 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
}
}