2026-09-02 15:54:33 -05:00 | | | //+------------------------------------------------------------------+
|
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
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "..\\FolderEncrypt.mqh"
|
2026-09-02 15:54:33 -05:00 | | | // incluimos PRNG random
|
| | | #include <TSN\\Crypto\\URandomPRNG.mqh>
|
| | | // Xoshiro256 para random
|
| | | #include <TSN\\Random\\Xoshiro256.mqh>
|
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);
|
| | | }
|
| | |
|
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);
|
2026-03-27 09:40:26 -05:00 | | |
|
| | | //---
|
2026-09-02 15:54:33 -05:00 | | | TSN::CFernet fernet;
|
| | | fernet.Key(key);
|
| | |
|
| | | //---
|
| | | TSN::CFolderOpsEncrypt folder_enc;
|
2026-03-27 09:40:26 -05:00 | | | folder_enc.AddLogFlags(LOG_ALL);
|
2026-09-02 15:54:33 -05:00 | | |
|
| | | // Seteamos el encriptoadr y su random
|
| | | folder_enc.Fernet(&fernet);
|
| | |
|
| | | // Steamos los inc
|
2026-03-27 09:40:26 -05:00 | | | folder_enc.SizeArrInclued(2);
|
| | | folder_enc.SetValIncluyed(0, "*.txt");
|
| | | folder_enc.SetValIncluyed(1, "*.csv");
|
2026-09-02 15:54:33 -05:00 | | | // Encryptamos
|
2026-03-27 09:40:26 -05:00 | | | folder_enc.SetInitialPass();
|
2026-09-02 15:54:33 -05:00 | | | // usamos el random URandomPRNG con bakcend de xho para el IV
|
| | | Print(folder_enc.EncryptFolder<TSN::CURandomPRNG<Xoshiro256>>(folder_path, true, true, TimeLocal(), ".enc"));
|
2026-03-27 09:40:26 -05:00 | | | }
|
| | | //+------------------------------------------------------------------+
|