| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include "stdafx.h"
- #include "OTSCrypt.h"
- #include "OTSHelper.h"
- #include <locale.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- namespace OTSMODEL
- {
- #define LICENSE_STRING_LENGTH_MAX 1024
- #define LICENSE_STRING_LENGTH_MIN 16
- #define LICENSE_KEYSTRING_LENGTH_MAX 1024
- #define LICENSE_KEYSTRING_LENGTH_MIN 16
- COTSCrypt::COTSCrypt(void)
- {
- }
- COTSCrypt::~COTSCrypt(void)
- {
- }
- void COTSCrypt::Encrypt(const LPCTSTR& a_sKey, CString& a_sLicense)
- {
- char* sKey = NULL;
- char* sLicense = NULL;
- #ifdef UNICODE
- sKey = new char[LICENSE_KEYSTRING_LENGTH_MAX];
- //wchar_t* wsKey = a_sKey.GetBuffer();
- COTSHelper::WCharToChar(a_sKey, sKey);
- //a_sKey.ReleaseBuffer();
- sLicense = new char[LICENSE_STRING_LENGTH_MAX];
- wchar_t* wsLicense = (wchar_t*)a_sLicense.GetBuffer();
- COTSHelper::WCharToChar(wsLicense, sLicense);
- a_sLicense.ReleaseBuffer();
- #else
- sKey = (char *)a_sKey;
- sLicense = a_sLicense.GetBuffer();
- #endif //UNICODE
- m_oCrypt.TransformString(sKey, sLicense);
- #ifdef UNICODE
- wchar_t* psz = new wchar_t[LICENSE_KEYSTRING_LENGTH_MAX];
- memset(psz, 0, sizeof(wchar_t) * LICENSE_KEYSTRING_LENGTH_MAX);
- COTSHelper::CharToWChar(sLicense, psz);
- CString cl(psz);
- a_sLicense = cl;
- delete[] psz;
- #else
- CString cl(sLicense);
- #endif
- //delete[] sKey;
- //delete[] sLicense;
- }
- void COTSCrypt::Decrypt(const LPCTSTR& a_sKey, CString& a_sLicense)
- {
- char* sKey = NULL;
- char* sLicense = NULL;
- #ifdef UNICODE
- sKey = new char[LICENSE_KEYSTRING_LENGTH_MAX];
- //wchar_t* wsKey = a_sKey.GetBuffer();
- COTSHelper::WCharToChar(a_sKey, sKey);
- //a_sKey.ReleaseBuffer();
- sLicense = new char[LICENSE_STRING_LENGTH_MAX];
- wchar_t* wsLicense = (wchar_t*)a_sLicense.GetBuffer();
- // begin tangchenglong modify 20140927
- // DWORD dwNum = WideCharToMultiByte(CP_ACP, NULL, wsLicense, -1, NULL, 0, NULL, FALSE);
- // WideCharToMultiByte(CP_ACP, NULL, wsLicense, -1, sLicense, dwNum, NULL, FALSE);
- COTSHelper::WCharToChar(wsLicense, sLicense);
- // end tangchenglong modify 20140927
- // COTSHelper::WCharToChar(wsLicense, sLicense);
- a_sLicense.ReleaseBuffer();
- #else
- sKey = (char *)a_sKey;
- sLicense = a_sLicense.GetBuffer();
- #endif
- m_oCrypt.TransformString(sKey, sLicense);
- // begin tangchenglong modify 20140927
- //#ifdef UNICODE
- // CString cl(sLicense);
- // a_sLicense = cl;
- // delete[] sKey;
- // delete[] sLicense;
- //#else
- // //a_sKey.ReleaseBuffer();
- // a_sLicense.ReleaseBuffer();
- //#endif
- #ifdef UNICODE
- wchar_t * psz = new wchar_t[LICENSE_KEYSTRING_LENGTH_MAX];
- memset(psz, 0, sizeof(wchar_t) * LICENSE_KEYSTRING_LENGTH_MAX);
- COTSHelper::CharToWChar(sLicense, psz);
- CString cl(psz);
- a_sLicense = cl;
- delete[] psz;
- delete[] sKey;
- delete[] sLicense;
- #else
- CString cl(sLicense);
- #endif
- // end tangchenglong modify 20140927
- }
- }
|