forked from nique_372/MQLArticles
63 lines
2.2 KiB
MQL5
63 lines
2.2 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| TestDec.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"
| |
// incluimos PRNG random
| |
#include <TSN\\Crypto\\URandomPRNG.mqh>
| |
// Xoshiro256 para random
| |
#include <TSN\\Random\\Xoshiro256.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| Script program start function |
| |
//+------------------------------------------------------------------+
| |
void OnStart()
| |
{
| |
//---
| |
const string folder_path = "MQLArticles\\File\\FolderOps\\Enc\\";
| |
| |
//--- Random para el IV
| |
TSN::CURandomPRNG<Xoshiro256>::s_rand.Seed(1000);
| |
// key 0 para reproducibilidad
| |
uchar key[CRYPTOBYLEO_FERNET_KEYBYTES];
| |
ArrayInitialize(key, 0);
| |
| |
//---
| |
TSN::CFernet fernet;
| |
fernet.Key(key);
| |
| |
//---
| |
TSN::CFolderOpsEncrypt folder_dec;
| |
folder_dec.AddLogFlags(LOG_ALL);
| |
folder_dec.Fernet(&fernet);
| |
folder_dec.SizeArrInclued(2);
| |
folder_dec.SetValIncluyed(0, "*.txt.enc");
| |
folder_dec.SetValIncluyed(1, "*.csv.enc");
| |
folder_dec.SetInitialPass();
| |
Print(folder_dec.DecryptFolder(folder_path, true, true, INT_MAX, "-"));
| |
| |
//--- Verificamos contenido
| |
const string files[] = {"data_importante.txt", "data_importante.csv"};
| |
for(int i = 0; i < ArraySize(files); i++)
| |
{
| |
::ResetLastError();
| |
int fh = FileOpen(folder_path + files[i], FILE_READ | FILE_TXT | FILE_COMMON);
| |
if(fh == INVALID_HANDLE)
| |
{
| |
Print("Fallo al abrir = ", files[i], " | last err = ", ::GetLastError());
| |
continue;
| |
}
| |
Print(files[i], " = ", FileReadString(fh));
| |
FileClose(fh);
| |
}
| |
}
| |
//+------------------------------------------------------------------+
|