77 lines
2.6 KiB
MQL5
77 lines
2.6 KiB
MQL5
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| TestEnc.mq5 |
|
||
|
|
//| Copyright 2026, Niquel Mendoza. |
|
||
|
|
//| https://www.mql5.com/es/users/nique_372 |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
||
|
|
#property link "https://www.mql5.com/es/users/nique_372"
|
||
|
|
#property version "1.00"
|
||
|
|
#property strict
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#include "..\\FolderEncrypt.mqh"
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| Script program start function |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
void OnStart()
|
||
|
|
{
|
||
|
|
//---
|
||
|
|
CRandomSimple random;
|
||
|
|
random.Seed(GetTickCount());
|
||
|
|
|
||
|
|
//---
|
||
|
|
const string folder_path = "MQLArticles\\File\\FolderOps\\Enc\\";
|
||
|
|
::FolderDelete(folder_path, FILE_COMMON); // Elimnamos si existe
|
||
|
|
|
||
|
|
//---
|
||
|
|
struct File
|
||
|
|
{
|
||
|
|
string path;
|
||
|
|
string content;
|
||
|
|
};
|
||
|
|
const File data[] =
|
||
|
|
{
|
||
|
|
{folder_path + "data_importante.txt", "contraseña: 123"},
|
||
|
|
{folder_path + "data_importante.csv", "contraseña: kjsdbfjksd"},
|
||
|
|
{folder_path + "data_importante.ini", "key=val"},
|
||
|
|
};
|
||
|
|
|
||
|
|
//---
|
||
|
|
const int t = ArraySize(data);
|
||
|
|
for(int i = 0; i < t; i++)
|
||
|
|
{
|
||
|
|
::ResetLastError();
|
||
|
|
const int fh = FileOpen(data[i].path, FILE_TXT | FILE_WRITE | FILE_COMMON);
|
||
|
|
if(fh == INVALID_HANDLE)
|
||
|
|
{
|
||
|
|
PrintFormat("Fallo al abrir el archivo = %s, ultimo error = %d", data[i].path, ::GetLastError());
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
FileWrite(fh, data[i].content);
|
||
|
|
FileClose(fh);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
//---
|
||
|
|
CFolderOpsEncrypt folder_enc;
|
||
|
|
folder_enc.AddLogFlags(LOG_ALL);
|
||
|
|
|
||
|
|
// Seteamos el encriptoadr y su random
|
||
|
|
folder_enc.Encryptor(&g_mqlarticles_encryptor);
|
||
|
|
folder_enc.RandomForEncryptor(&random);
|
||
|
|
// Creamos la clave aleatoria
|
||
|
|
g_mqlarticles_encryptor.SetAleatoryKey(CRYPT_AES256, RandomSimpleGenerateRandomUchar, &random, 32, 128);
|
||
|
|
// Steamos los inc
|
||
|
|
folder_enc.SizeArrInclued(2);
|
||
|
|
folder_enc.SetValIncluyed(0, "*.txt");
|
||
|
|
folder_enc.SetValIncluyed(1, "*.csv");
|
||
|
|
// Encryptamos
|
||
|
|
string key = "u";
|
||
|
|
folder_enc.SetInitialPass();
|
||
|
|
Print(folder_enc.EncryptFolder(folder_path, true, key, CRYPT_AES256, true, ".enc"));
|
||
|
|
PrintFormat("Key generada = '%s'", key);
|
||
|
|
}
|
||
|
|
//+------------------------------------------------------------------+
|