7/5/1
This commit is contained in:
83
lib/controller/functions/encrypt.dart
Normal file
83
lib/controller/functions/encrypt.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
//
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
|
||||
class KeyEncryption {
|
||||
static final _key = encrypt.Key.fromUtf8('mehmetDEV@2101'); // ضع مفتاحك هنا
|
||||
|
||||
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('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.');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user