MQLArticles/Utils/File/FolderOps/Test/TestEnc.mq5
84 righe
2,7 KiB
MQL5
Nique_372
2026-09-02 15:54:33 -05:00
//+------------------------------------------------------------------+
Nique_372
2026-03-27 09:40:26 -05:00
//| 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
Nique_372
2026-10-22 21:57:02 -05:00
#define MQLARTICLES_FOLDEROPS_ENABLE_LOGS
Nique_372
2026-03-27 09:40:26 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\FolderEncrypt.mqh"
Nique_372
2026-09-02 15:54:33 -05:00
// incluimos PRNG random
#include <TSN\\Crypto\\URandomPRNG.mqh>
// Xoshiro256 para random
#include <TSN\\Random\\Xoshiro256.mqh>
Nique_372
2026-03-27 09:40:26 -05:00
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
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);
}
Nique_372
2026-09-02 15:54:33 -05:00
//--- Random para el IV
TSN::CURandomPRNG<Xoshiro256>::s_rand.Seed(1000);
// key 0 para reproducibilidad
uchar key[CRYPTOBYLEO_FERNET_KEYBYTES];
ArrayInitialize(key, 0);
Nique_372
2026-03-27 09:40:26 -05:00
//---
Nique_372
2026-09-02 15:54:33 -05:00
TSN::CFernet fernet;
fernet.Key(key);
//---
TSN::CFolderOpsEncrypt folder_enc;
// Seteamos el encriptoadr y su random
folder_enc.Fernet(&fernet);
// Steamos los inc
Nique_372
2026-03-27 09:40:26 -05:00
folder_enc.SizeArrInclued(2);
folder_enc.SetValIncluyed(0, "*.txt");
folder_enc.SetValIncluyed(1, "*.csv");
Nique_372
2026-09-02 15:54:33 -05:00
// Encryptamos
Nique_372
2026-10-22 21:57:02 -05:00
folder_enc.SetInitialPass(CRYPTOBYLEO_FERNET_UTCTIME);
Nique_372
2026-09-02 15:54:33 -05:00
// usamos el random URandomPRNG con bakcend de xho para el IV
Nique_372
2026-10-22 21:57:02 -05:00
folder_enc.EncryptFolder<TSN::CURandomPRNG<Xoshiro256>>(folder_path, true, true, ".enc");
Nique_372
2026-03-27 09:40:26 -05:00
}
//+------------------------------------------------------------------+