This commit is contained in:
Hamza-Ayed
2024-07-05 23:46:05 +03:00
parent dc4677a6bf
commit 23ecaba97c
17 changed files with 310 additions and 225 deletions

View File

@@ -1,21 +1,19 @@
import 'package:encrypt/encrypt.dart' as encrypt;
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:encrypt/encrypt.dart' as encrypt;
//
import 'dart:convert';
import 'dart:math';
import 'package:encrypt/encrypt.dart' as encrypt;
import '../../constant/api_key.dart';
class KeyEncryption {
static final _key = encrypt.Key.fromUtf8('mehmetDEV@2101'); // ضع مفتاحك هنا
// استخدم مفتاح بطول 32 حرفًا
static final _key = encrypt.Key.fromUtf8(AK.keyOfApp);
static final _iv =
encrypt.IV.fromLength(16); // توليد تهيئة عشوائية بطول 16 بايت
static String encryptKey(String key) {
final iv = encrypt.IV.fromLength(16); // توليد تهيئة عشوائية
final encrypter =
encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
final encrypted = encrypter.encrypt(key, iv: iv);
final result = iv.bytes + encrypted.bytes; // تضمين التهيئة مع النص المشفر
final encrypted = encrypter.encrypt(key, iv: _iv);
final result = _iv.bytes + encrypted.bytes; // تضمين التهيئة مع النص المشفر
return base64Encode(result);
}
@@ -29,55 +27,3 @@ class KeyEncryption {
return encrypter.decrypt(encrypted, iv: iv);
}
}
// class KeyEncryption {
// static final _key = encrypt.Key.fromUtf8('7'); // ضع مفتاحك هنا
//
// static String encryptKey(String key) {
// final iv = encrypt.IV.fromLength(16); // توليد تهيئة عشوائية
// final encrypter =
// encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
// final encrypted = encrypter.encrypt(key, iv: iv);
// final result = iv.bytes + encrypted.bytes; // تضمين التهيئة مع النص المشفر
// return base64Encode(result);
// }
//
// static String decryptKey(String encryptedKey) {
// final decoded = base64Decode(encryptedKey);
// final iv = encrypt.IV(decoded.sublist(0, 16)); // استخراج التهيئة
// final encrypted =
// encrypt.Encrypted(decoded.sublist(16)); // استخراج النص المشفر
// final encrypter =
// encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
// return encrypter.decrypt(encrypted, iv: iv);
// }
// }
// class KeyEncryption {
// static final _key =
// encrypt.Key.fromUtf8('32-character-key....'); // ضع مفتاحك هنا
//
// static String encryptKey(String key) {
// final iv = encrypt.IV.fromLength(16); // توليد تهيئة عشوائية
// final encrypter =
// encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
// final encrypted = encrypter.encrypt(key, iv: iv);
// final result = iv.bytes + encrypted.bytes; // تضمين التهيئة مع النص المشفر
// return base64Encode(result);
// }
//
// static Future<void> storeApiKeys(List<String> apiKeys) async {
// final encryptedKeys = apiKeys.map((key) => encryptKey(key)).toList();
// final response = await http.post(
// Uri.parse('https://yourdomain.com/store_keys.php'),
// body: jsonEncode({'keys': encryptedKeys}),
// headers: {'Content-Type': 'application/json'},
// );
//
// if (response.statusCode == 200) {
// print('Keys stored successfully.');
// } else {
// print('Failed to store keys.');
// }
// }
// }