first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// 与 uniApp 端 utils/crypto.js 完全一致的密码混淆算法(XOR + Base64)。
|
||||
/// 注意:仅防明文存储,非强加密。
|
||||
const String _secretKey = 'QIANGBAO_AI_JIZHANG_2024';
|
||||
|
||||
String encryptPassword(String password) {
|
||||
if (password.isEmpty) return '';
|
||||
final chars = password.codeUnits;
|
||||
final keyUnits = _secretKey.codeUnits;
|
||||
final encrypted = String.fromCharCodes([
|
||||
for (var i = 0; i < chars.length; i++) chars[i] ^ keyUnits[i % keyUnits.length],
|
||||
]);
|
||||
return base64Encode(utf8.encode(encrypted));
|
||||
}
|
||||
|
||||
String decryptPassword(String encrypted) {
|
||||
if (encrypted.isEmpty) return '';
|
||||
try {
|
||||
final decoded = utf8.decode(base64Decode(encrypted));
|
||||
final chars = decoded.codeUnits;
|
||||
final keyUnits = _secretKey.codeUnits;
|
||||
return String.fromCharCodes([
|
||||
for (var i = 0; i < chars.length; i++) chars[i] ^ keyUnits[i % keyUnits.length],
|
||||
]);
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user