Files
EgtLock/LockId.cpp
T
Dario Sassi 07e9914302 EgtLock 1.6g8 :
- aggiunta gestione chiavi hardware OxySec
- spostati Base64 e Crc32 in General.
2015-07-29 07:03:48 +00:00

134 lines
3.7 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : ProtectionId.cpp Data : 28.07.15 Versione : 1.6g8
// Contenuto : Funzioni per gestione/calcolo Id protezione.
//
//
//
// Modifiche : 28.07.15 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//------------------ Include -------------------------------------------------
#include "stdafx.h"
#include "MachineId.h"
#include "DongleId.h"
#include "Obfuscate.h"
#include "/EgtDev/Include/EgtBase64.h"
#include "/EgtDev/Include/EgtCrc32.h"
#include "/EgtDev/Include/SELkLockId.h"
using namespace std ;
//----------------------------------------------------------------------------
static int s_nLockType = KEY_LOCK_TYPE_ANY ;
//----------------------------------------------------------------------------
bool
SetLockType( int nType)
{
if ( nType != KEY_LOCK_TYPE_ANY &&
nType != KEY_LOCK_TYPE_SW &&
nType != KEY_LOCK_TYPE_HW)
return false ;
s_nLockType = nType ;
return true ;
}
//----------------------------------------------------------------------------
int
GetLockType( void)
{
return s_nLockType ;
}
//----------------------------------------------------------------------------
bool
GetLockId( string& sLockId)
{
switch ( s_nLockType) {
default : // KEY_LOCK_TYPE_ANY
if ( GetDongleId( sLockId))
return true ;
return GetMachineId( sLockId) ;
case KEY_LOCK_TYPE_SW :
return GetMachineId( sLockId) ;
case KEY_LOCK_TYPE_HW :
return GetDongleId( sLockId) ;
}
}
//----------------------------------------------------------------------------
bool
GetLockId2( string& sLockId)
{
string sTmp ;
if ( ! GetLockId( sTmp))
return false ;
return ConvertLockIdToLockId2( sTmp, sLockId) ;
}
//------------------------------------------------------------------------------------
bool
ConvertLockIdToLockId2( const string& sLockId, string& sLockId2)
{
// eseguo Mix + CRC32 + Base64
string sAux = sLockId ;
if ( ! MixLockId( sAux))
return false ;
AddCrc32ToString( sAux) ;
return B64Encode( sAux, sLockId2) ;
}
//------------------------------------------------------------------------------------
bool
ConvertLockId2ToLockId( const string& sLockId2, string& sLockId)
{
// eseguo decodifica da Base64
if ( ! B64Decode( sLockId2, sLockId))
return false ;
// eseguo test e rimozione CRC32
if ( ! TestCrc32AndRemoveFromString( sLockId))
return false ;
// eseguo demixing
if ( ! MixLockId( sLockId))
return false ;
return true ;
}
//------------------------------------------------------------------------------------
bool
ConvertLockIdToScramKey( const string& sLockId, string& sScramKey)
{
// eseguo Mix
sScramKey = sLockId ;
if ( ! MixLockId( sScramKey))
return false ;
// eseguo scramble
if ( ! ScrambleLockId( sScramKey))
return false ;
// aggiungo CRC32
AddCrc32ToString( sScramKey) ;
return true ;
}
//------------------------------------------------------------------------------------
bool
ConvertLockId2ToScramKey( const string& sLockId2, string& sScramKey)
{
// eseguo decodifica da Base64
if ( ! B64Decode( sLockId2, sScramKey))
return false ;
// eseguo test e rimozione CRC32
if ( ! TestCrc32AndRemoveFromString( sScramKey))
return false ;
// eseguo scramble
if ( ! ScrambleLockId( sScramKey))
return false ;
// aggiungo CRC32
AddCrc32ToString( sScramKey) ;
return true ;
}