Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

monsieur_jj

@monsieur_jj
About
Posts
218
Topics
104
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Question about inserting into dbf file
    M monsieur_jj

    I have this code below that updates a dbf file now this code before also updates a cdx file but I changed something in the values I added now the cdx file is not inline with the dbf. I have tried to "reindex" and "SET INDEX TO" however everytime I do an insert in the dbf table the modified date of the cdx file stays the same as the old one. Should the cdx be updated everytime there is something new inserted?

    DIAGNOSTICS_CHECKPOINT;
    LOG(L"AutoLoad File Connection String");
    LOG(this->_connectionstring.c_str());
    cnn->CursorLocation = adUseClient;
    try { hr = cnn->Open(this->_connectionstring.c_str(), L"", L"", 0); }
    catch (_com_error& e)
    { wss.str(L"");
    wss << L"Opening the AutoloadFile connection from '"
    << _connectionstring.c_str()
    << L"' has failed (COM Error: " << e.ErrorMessage()
    << L", " << hr << L")."
    << std::endl;
    LOG(wss.str().c_str());
    throw;
    }

    DIAGNOSTICS\_CHECKPOINT;
    wss.str(L"");
    wss << L"INSERT INTO " 
    	<< this->\_tablename
    	<< L" VALUES ('" 
    	<< trans\_id << L"','" 
    	<< params << L"','"
    	<< status << L"',"
    	<< rec\_no << L")"
    	;
    
    DIAGNOSTICS\_CHECKPOINT;
    std::wstring sql(wss.str().c\_str());
    LOG(L"Executing INSERT into the autoload file");
    LOG(sql.c\_str());
    try 
    {	rs->Open(sql.c\_str(), cnn.GetInterfacePtr(), 
    		adOpenForwardOnly, adLockReadOnly, adCmdText);
    }
    catch (\_com\_error& e)
    {	wss.str(L"");
    	wss << L"Executing SQL statement:\\n" 
    		<< sql.c\_str() 
    		<< L"'\\n...has failed (COM Error: " 
    		<< e.Error() << L", '"
    		<< e.ErrorMessage()
    		<< L"')." 
    		<< std::endl;
    	LOG(wss.str().c\_str());
    	throw;
    }
    
    ATL / WTL / STL database question com help

  • FindFile file type question
    M monsieur_jj

    Hi all, I am new to vb and I am trying to get the file type of every file found during findfile here is my code:

    iSearchHandle = FindFirstFile(SrcDir, pFindFileBuff)
    If iSearchHandle <> INVALID_HANDLE_VALUE Then

        strFile = TrimNull(pFindFileBuff.cFileName)
        Do While strFile <> ""
            Do While FindNextFile(iSearchHandle, pFindFileBuff)
            strFile = TrimNull(pFindFileBuff.cFileName)
            If strFile <> "." And strFile <> ".." Then
            strFile = strDir + "\\" + strFile
            'strLen = Len(strFile)
            
            fileType = Right$(strFile, 4)
    

    I tried using Right$ to get the file type for example "TonyRobertson.ppsx", ,"version2.5.0.doc", "IMIT031211_TonyRobertson.ppt" and "MARBLES.G4" by using that I get ppsx, .doc, .ppt and S.G4, is there another way to get the right format? Thanks, Jj

    Visual Basic question tutorial

  • Removing else in this statements How?
    M monsieur_jj

    Hi all, I had my code reviewed and I had a comment that its best to remove the else in this statements:

    LRESULT CMainDlg::OnInstall(WORD, WORD wID, HWND, BOOL& )
    {
    string LaunchInstaller;
    string InstallFolder;
    InstallClass installclass;

    TCHAR tcItemText\[MAXBYTES\];
    
    if(UpdateList.GetItemText(Select, tcItemText, MAXBYTES))
    {
    InstallFolder = tcItemText;
    LaunchInstaller = installclass.ConstructInstallerKey(IDS\_MANAGEKEY, InstallFolder);
    	if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    	{
    		return 0;
    	}
    	else 
    	{
    		LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEKEY, InstallFolder);
    		if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    		{
    			return 0;
    		}
    		else
    		{
    			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEASIANKEY, InstallFolder);
    			if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    			{
    				return 0;
    			}
    			else
    			{
    			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITECHINAKEY, InstallFolder);
    				if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    				{
    					return 0;
    				}
    			}
    		}
    	}
    }
    else
    {
    MessageBox ( \_T("Please choose an item to install"), \_T("Redmap Update Manager"), MB\_ICONWARNING );
    }
    return 0;
    

    }

    Any suggestions on how the code should look like? Thanks, Jayjay

    C / C++ / MFC question announcement

  • ATLASSERT question
    M monsieur_jj

    Hi all, Does ATLASSERT run during release mode? should I enclose it with ifdef debug? Or it doesnt do anything on release mode? Thanks, Jayjay

    C / C++ / MFC question debugging announcement

  • what does this error mean?
    M monsieur_jj

    Hi all, This only happens on the release version of my project and it does not happen on the debug version. Also I have the same additional dependencies.

    SiteCode.obj : error LNK2019: unresolved external symbol "unsigned int __cdecl hash(char *)" (?hash@@YAIPAD@Z) referenced in function "public: int __thiscall CSiteCode::ReportNICInfoMP(int,class CDeviceLocationInformationList &,class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &,char *)" (?ReportNICInfoMP@CSiteCode@@QAEHHAAVCDeviceLocationInformationList@@AAV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@PAD@Z)
    1>SiteCode.obj : error LNK2019: unresolved external symbol "unsigned int __cdecl calc_hashnr_new(char const *,unsigned int)" (?calc_hashnr_new@@YAIPBDI@Z) referenced in function "public: int __thiscall CSiteCode::ReportNICInfoMP(int,class CDeviceLocationInformationList &,class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &,char *)" (?ReportNICInfoMP@CSiteCode@@QAEHHAAVCDeviceLocationInformationList@@AAV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@PAD@Z)
    1>SiteCode.obj : error LNK2019: unresolved external symbol "unsigned int __cdecl calc_hashnr(char const *,unsigned int)" (?calc_hashnr@@YAIPBDI@Z) referenced in function "public: int __thiscall CSiteCode::ReportNICInfoMP(int,class CDeviceLocationInformationList &,class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &,char *)" (?ReportNICInfoMP@CSiteCode@@QAEHHAAVCDeviceLocationInformationList@@AAV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@PAD@Z)
    1>SiteCode.obj : error LNK2019: unresolved external symbol "unsigned long __cdecl hashpjw(char *,unsigned int)" (?hashpjw@@YAKPADI@Z) referenced in function "public: int __thiscall CSiteCode::ReportNICInfoMP(int,class CDeviceLocationInformationList &,class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > &,char *)" (?ReportNICInfoMP@CSiteCode@@QAEHHAAVCDeviceLocationInformationList@@AAV?$CStringT@_WV?$StrTraitATL@_WV?$ChTraitsCRT@_W@ATL@@@ATL@@@ATL@@PAD@Z)
    1>SiteCode.obj : error LNK2019: unresolved external symbol "void __cdecl Add2ByteChecksum(unsigned char *)" (?Add2ByteChecksum@@YAXPAE@Z) referenced in function "public: class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT&

    C / C++ / MFC announcement c++ cryptography debugging help

  • What does this error mean?
    M monsieur_jj

    Hi all What does this error mean:

    1>nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in UpdatePanel.obj
    1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
    1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
    1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj)
    1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)

    This happens here:

    #include <afxdb.h> // MFC database classes

    #include <winsock2.h>

    #include <tchar.h>

    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h> // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT

    //#include "stdafx.h"
    #include "..\\Common\\smtpconnection2.h"
    BOOL CSMTPConnection2::Connect(LPCTSTR lpszHostDomain,
    DWORD dwTimeout /*= 10000*/) throw()
    {
    CSimpleArray<CAtlString> arrSMTP;
    _GetSMTPList(lpszHostDomain, arrSMTP);
    for(int i=0; i<arrSMTP.GetSize(); i++)
    {
    if(CSMTPConnection::Connect(arrSMTP[i], dwTimeout) == TRUE)
    return TRUE;
    }
    return FALSE;
    }

    void CSMTPConnection2::_GetSMTPList(LPCTSTR lpszHostDomain,
    CSimpleArray<CAtlString>& arrSMTP)
    {
    PDNS_RECORD pRec = NULL;
    if(DnsQuery(lpszHostDomain, DNS_TYPE_MX, DNS_QUERY_STANDARD,
    NULL, &pRec, NULL) == ERROR_SUCCESS)
    {
    PDNS_RECORD pRecOrig = pRec;
    while(pRec)
    {
    if(pRec->wType == DNS_TYPE_MX)
    arrSMTP.Add(pRec->Data.MX.pNameExchange);
    pRec = pRec->pNext;
    }
    DnsRecordListFree(pRecOrig,DnsFreeRecordList);
    }
    }

    What do you think? Thanks, Jayjay

    C / C++ / MFC c++ database help question discussion

  • Microsoft Enhanced Cryptographic Provider question
    M monsieur_jj

    Hi all, I have used this csp when I initiate my decryption:

    CryptAcquireContext(&hProv,NULL,MS_ENHANCED_PROV,PROV_RSA_FULL,0);

    I have also checked http://msdn.microsoft.com/en-us/library/aa386986(VS.85).aspx[^] and have verified that 3des is supported. Is it possible that http://www.codeproject.com/KB/web-security/Cryptography_MD5_TriDES.aspx?display=Print[^] may have a different output from a c++ version of the code? Can anyone give me a c# encryption and an equal c++ decryption examples? Thanks, Jayjay

    C / C++ / MFC security question csharp c++ visual-studio

  • Please help me with my decryption it almost works
    M monsieur_jj

    Hi David, These are the list of what is supported:

    Listing Available Providers:
    Provider type Provider Name
    _____________ _____________________________________
    1 Gemplus GemSAFE Card CSP v1.0
    1 Infineon SICRYPT Base Smart Card CSP
    1 Microsoft Base Cryptographic Provider v1.0
    13 Microsoft Base DSS and Diffie-Hellman Cryptographic Provider
    3 Microsoft Base DSS Cryptographic Provider
    18 Microsoft DH SChannel Cryptographic Provider
    1 Microsoft Enhanced Cryptographic Provider v1.0
    13 Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider

       24       Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype
    

    )
    5 Microsoft Exchange Cryptographic Provider v1.0
    12 Microsoft RSA SChannel Cryptographic Provider
    1 Microsoft Strong Cryptographic Provider
    1 Schlumberger Cryptographic Service Provider

    Provider types and provider names have been listed.
    Listing Available Provider Types:
    Provider type Provider Type Name
    _____________ _____________________________________
    1 RSA Full (Signature and Key Exchange)
    3 DSS Signature
    5 Microsoft Office Outlook/Exchange Cryptographic Service Provider

       12       RSA SChannel
       13       DSS Signature with Diffie-Hellman Key Exchange
       18       Diffie-Hellman SChannel
       24       RSA Full and AES
    

    I read at msdn that Microsoft Enhanced Cryptographic Provider v1.0 supports triple DES now I am confused to what the problem really is. Thanks, Jayjay

    C / C++ / MFC help

  • Please help me with my decryption it almost works
    M monsieur_jj

    Hi Pallini, Sorry never mind the message box output i forgot to comment that. Can anyone tell me the difference between the C# code and mine? Im pretty sure pkcs5 is the same at pkcs7 and i got all inputs the same. Thanks, Jayjay

    C / C++ / MFC help

  • Please help me with my decryption it almost works
    M monsieur_jj

    This is my code: It gives me true when I perform the function crypt decrypt its just that I am expecting this output : aHR0cDovL2xvY2FsaG9zdDo4MDgwL015V2ViL21hbmFnZXBvaW50L21hbmFnZXBvaW50MzQxLnppcA== Then when I decode it Ill should get a link but instead cryptdecrypt gives me trash which I cant convert to the right link

    LPTSTR Base64Decode(LPCTSTR lpData, DWORD dwSize)
    {
    DWORD dwResult = 0;
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult,NULL,NULL))
    {
    LPTSTR lpszBase64Decoded = new TCHAR[dwResult+(sizeof(TCHAR) * 2)];
    memset(lpszBase64Decoded,0,dwResult);
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64,(BYTE *)lpszBase64Decoded, &dwResult,NULL,NULL))
    {
    *(LPWORD)(lpszBase64Decoded + (dwResult / sizeof(TCHAR))) = 0;

    		return lpszBase64Decoded;
    	}
    }
    return NULL;
    

    }

    LPTSTR Base64Encode(LPCBYTE lpData, DWORD dwSize, BOOL bStripCRLF, DWORD *dwBufSize)
    {
    DWORD dwResult = 0;
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult))
    {
    LPTSTR lpszBase64 = new TCHAR[dwResult];
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, lpszBase64, &dwResult))
    {
    TCHAR pByteLF = *(LPWORD)(lpszBase64 + dwResult -1);
    TCHAR pByteCR = *(LPWORD)(lpszBase64 + dwResult -2);
    if(pByteCR == 0x0D && pByteLF == 0x0A)
    {
    *(LPWORD)(lpszBase64 + dwResult -2) = 0;
    }
    *dwBufSize = dwResult;
    return lpszBase64;
    }
    }
    return NULL;
    }

    BYTE* Base64Decode2(LPCTSTR lpData, DWORD dwSize, DWORD *dwBufSize)
    {
    DWORD dwResult = 0;
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult,NULL,NULL))
    {
    BYTE * decodedStr;
    decodedStr = new BYTE;
    LPTSTR lpszBase64Decoded = new TCHAR[dwResult+(sizeof(TCHAR) * 2)];
    memset(decodedStr,0,dwResult);
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64,decodedStr, &dwResult,NULL,NULL))
    {
    *dwBufSize = dwResult;
    return decodedStr;
    }
    }
    return NULL;
    }
    LPTSTR Base64Encode2(BYTE* lpData, DWORD dwSize, BOOL bStripCRLF, DWORD *dwbufSize)
    {
    DWORD dwResult = 0;
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult))
    {
    LPTSTR lpszBase64 = new TCHAR[dwResult];
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, lpszBase64, &dwResult))
    {
    TCHAR pByteLF = *(LPWORD)(lpszBase64 + dwResult -1);
    TCHAR pByteCR = *(LPWORD)(lpszBase64 + dwResult -2);
    if(pByteCR == 0x0D && pByteLF == 0x0A)
    {
    *(LPWORD)(

    C / C++ / MFC help

  • How does this translate to c++
    M monsieur_jj

    Hi all, How does this translate to c++:

    string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
    HashAlgorithm XHash = HashAlgorithm.Create("MD5");
    byte[] keyArray = XHash.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
    XHash.Clear();
    TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
    tdes.Key = keyArray;
    tdes.Mode = CipherMode.ECB;
    tdes.Padding = PaddingMode.PKCS7;

    This is what I did but i am not sure if its correct because I didnt do the UTF8Encoding part.

    TCHAR szKey[] = _T("Key");
    DWORD pwlen = _tcslen(szKey);
    result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
    result = CryptHashData(hHash,(BYTE *)szKey,pwlen,0);
    result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
    BYTE PadMode = CRYPT_MODE_ECB;
    result = CryptSetKeyParam(hKey, PKCS5_PADDING, &PadMode, 0);

    Please help me clarify things. Thanks, Jayjay

    C / C++ / MFC c++ help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi David, I am kinda confused about how the padding will be can you explain how will the code look like? Thanks, jayjay

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi David, Is PKCS5 of c++ win api the same ast PKCS 7 of C# or .net? I will research on this, or I have to ask to change the way of encrypting. Thanks, Jayjay

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi David, What do you think that can help me know? The c# developer said it is standard so it can be fully translated to c++ Thanks, Jayjay

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi David, Thanks I have also tried that as you can see at the code I posted, where will I use the blobheader? Is it just a container of the modes and 3des algorithm? Thanks for the continuous help, Jayjay

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi David , This is the whole solution of the c# application used for the encryption: Link[^] Yup I have tested it and kinda reversed engineered it to imitate the c# conversion, I just revised it a bit that both byte[] toEncryptArray = Convert.FromBase64String(toEncrypt); and return Convert.ToBase64String(resultArray, 0, resultArray.Length); are used instead of using the UTF8 conversion although it is still being used when converting the key. Please enlighten me Thanks, Jayjay

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Ooops yep I did and I get a bad data error i forgot the number, i did put getlasterror i wasnt able to paste it here.

    C / C++ / MFC help

  • CryptDecrypt Failure please help
    M monsieur_jj

    Hi all, First of all props to Randor for helping me and giving me a base code now I modified his code and this is it:

    #include <iostream>
    #include <tchar.h>
    #include <windows.h>
    #include <Wincrypt.h>
    #include <Xenroll.h>
    #include <atlenc.h>
    #include <atlcrypt.h>

    #pragma comment(lib, "crypt32.lib")//n7M41mbWvrA=
    BYTE* Base64Decode2(LPCTSTR lpData, DWORD dwSize, DWORD *dwBufSize)
    {
    DWORD dwResult = 0;
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult,NULL,NULL))
    {
    BYTE * decodedStr;
    decodedStr = new BYTE;
    LPTSTR lpszBase64Decoded = new TCHAR[dwResult+(sizeof(TCHAR) * 2)];
    memset(decodedStr,0,dwResult);
    if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64,decodedStr, &dwResult,NULL,NULL))
    {
    *dwBufSize = dwResult;
    return decodedStr;
    }
    }
    return NULL;
    }

    LPTSTR Base64Encode2(BYTE* lpData, DWORD dwSize, BOOL bStripCRLF, DWORD *dwbufSize)
    {
    DWORD dwResult = 0;
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult))
    {
    LPTSTR lpszBase64 = new TCHAR[dwResult];
    if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, lpszBase64, &dwResult))
    {
    TCHAR pByteLF = *(LPWORD)(lpszBase64 + dwResult -1);
    TCHAR pByteCR = *(LPWORD)(lpszBase64 + dwResult -2);
    if(pByteCR == 0x0D && pByteLF == 0x0A)
    {
    *(LPWORD)(lpszBase64 + dwResult -2) = 0;
    }
    *dwbufSize = dwResult;
    return lpszBase64;
    }
    }
    return NULL;
    }
    DWORD TripleDESdecrypt2(TCHAR *cyphertext,DWORD ctlen,TCHAR *passwd,DWORD pwlen,BYTE *plaintext,DWORD *ptlen)
    {
    HCRYPTPROV hProv;
    HCRYPTHASH hHash;
    HCRYPTKEY hKey;
    DWORD dwSizeNeeded =0;

    CryptAcquireContext(&hProv,NULL,MS\_STRONG\_PROV,PROV\_RSA\_FULL,0);
    CryptCreateHash(hProv,CALG\_MD5,0,0,&hHash);
    CryptHashData(hHash,(BYTE \*)passwd,pwlen,0);
    CryptDeriveKey(hProv,CALG\_3DES,hHash,0,&hKey);
    DWORD dMode = CRYPT\_MODE\_ECB;
        CryptSetKeyParam(hKey, PKCS5\_PADDING, reinterpret\_cast<const BYTE \*>(&dMode), 0);
    if(\*ptlen >= ctlen)
    {
    
    	memcpy(plaintext,cyphertext,\*ptlen);
    	BOOL result = CryptDecrypt(hKey,NULL,1,0,plaintext,&ctlen);
    	\*ptlen=ctlen;
    }
    else
    {
    	dwSizeNeeded = ctlen \* sizeof(TCHAR);
    }
    CryptDestroyKey(hKey);
    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv,0);
    return dwSizeNeeded;
    

    }
    int main()
    {

    BYTE\* decodedStr;
    HCRYPTPROV hCryptProv;
    HCRYPTHASH hHash = 0;
    HCRYPTKEY hKey = 0;
    
    TCHAR szKey\[\] = \_T("h3bmull3r
    
    C / C++ / MFC help

  • decrypting question
    M monsieur_jj

    Hi David, You have been a great help so far, by the way i have tested your code it works however I still need to do some tweaking as I can't convert "Zed5OmjUWs8=" to "test" and also what is this for:

    ICryptoTransform cTransform = tdes.CreateDecryptor();
    byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

    Thanks, Jayjay

    C / C++ / MFC csharp question workspace

  • decrypting question
    M monsieur_jj

    Hi all, I have this c# decrypting code:

    public static string Decrypt(string cipherString, bool useHashing)
    {
    byte[] keyArray;
    byte[] toEncryptArray = Convert.FromBase64String(cipherString);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            //Get your key from config file to open the lock!
            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
            
            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
                keyArray = UTF8Encoding.UTF8.GetBytes(key);
    
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
    
            
            ICryptoTransform cTransform = tdes.CreateDecryptor();
            byte\[\] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                        
            tdes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
    

    public static string Encrypt(string toEncrypt, bool useHashing)
    {
    byte[] keyArray;
    byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            // Get the key from config file
            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
            //System.Windows.Forms.MessageBox.Show(key);
            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
                keyArray = UTF8Encoding.UTF8.GetBytes(key);
    
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
    
            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte\[\] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray
    
    C / C++ / MFC csharp question workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups