6ce68192a2
- aggiunte funzioni exe e lua Base64Encode e Base64Decode.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2025-2025
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_Base64.cpp Data : 03.11.25 Versione : 2.7k1
|
|
// Contenuto : Funzioni per codificare/decodificare in Base64.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 03.11.25 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EgtStringConverter.h"
|
|
#include "/EgtDev/Include/EgtBase64.h"
|
|
#include <fstream>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeBase64Encode( const string& sFile, string& sB64Dest)
|
|
{
|
|
// apro il file in modo binario
|
|
ifstream InFile( stringtoW( sFile), ios::in | ios::binary, _SH_DENYWR) ;
|
|
if ( InFile.fail()) {
|
|
if ( InFile.is_open())
|
|
InFile.close() ;
|
|
return false ;
|
|
}
|
|
// leggo il file
|
|
string sSou( istreambuf_iterator<char>( InFile), {}) ;
|
|
// lo chiudo
|
|
if ( InFile.is_open())
|
|
InFile.close() ;
|
|
|
|
// converto in Base64
|
|
return B64Encode( sSou, sB64Dest) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeBase64Decode( const string& sB64Sou, const string& sFile)
|
|
{
|
|
// converto da Base64
|
|
string sDest ;
|
|
if ( ! B64Decode( sB64Sou, sDest))
|
|
return false ;
|
|
|
|
// apro il file in modo binario
|
|
ofstream OutFile( stringtoW( sFile), ios::out | ios::binary, _SH_DENYWR) ;
|
|
if ( ! OutFile.good()) {
|
|
if ( OutFile.is_open())
|
|
OutFile.close() ;
|
|
return false ;
|
|
}
|
|
// scrivo sul file
|
|
OutFile.write( sDest.data(), sDest.size()) ;
|
|
// lo chiudo
|
|
if ( OutFile.is_open())
|
|
OutFile.close() ;
|
|
return true ;
|
|
}
|