Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

Is there a library in VC++ that does MD5 encryption and decryption?

Thanks,
Garyc
Posted

Apparently[^], there is.
 
Share this answer
 
There is Windows Cryptography [^], for instance.
:)
 
Share this answer
 
v2
hi i have decryption sample code...

Here is the md5Capi.h code.....>>>>

// md5Capi.h: interface for the Cmd5Capi class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MD5CAPI_H__438D2BEF_6F1B_4C5C_830F_0E7B6D1FD7E2__INCLUDED_)
#define AFX_MD5CAPI_H__438D2BEF_6F1B_4C5C_830F_0E7B6D1FD7E2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#include <wincrypt.h> // Cryptographic API Prototypes and Definitions
#endif
// Cryptographic API Prototypes and Definitions


class Cmd5Capi
{
public:
CString &Digest(CString & csBuffer);
CString &GetDigest(void);

Cmd5Capi(CString & csBuffer);
Cmd5Capi();
virtual ~Cmd5Capi();
CString csDigest;
};




#endif // !defined(AFX_MD5CAPI_H__438D2BEF_6F1B_4C5C_830F_0E7B6D1FD7E2__INCLUDED_)




////////////////////////////////////////////////

AND md5Capi.cpp CODE>>>>>>>



//////////////////////////////////////////////////////////////////////
// md5Capi.cpp: implementation of the Cmd5Capi class.
// Calcule MD5 Digest using the WIN Crypto API.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "md5Capi.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Cmd5Capi::Cmd5Capi()
{
csDigest.Empty();
}

Cmd5Capi::Cmd5Capi(CString & csBuffer)
{
Digest(csBuffer);
}



Cmd5Capi::~Cmd5Capi()
{

}

CString &Cmd5Capi::GetDigest(void)
{
return csDigest;

}


CString &Cmd5Capi::Digest(CString & csBuffer)
{
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash;
BYTE bHash[0x7f];
DWORD dwHashLen= 16; // The MD5 algorithm always returns 16 bytes.
DWORD cbContent= csBuffer.GetLength();
BYTE* pbContent= (BYTE*)csBuffer.GetBuffer(cbContent);


if(CryptAcquireContext(&hCryptProv,
NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET))
{

if(CryptCreateHash(hCryptProv,
CALG_MD5, // algorithm identifier definitions see: wincrypt.h
0, 0, &hHash))
{
if(CryptHashData(hHash, pbContent, cbContent, 0))
{

if(CryptGetHashParam(hHash, HP_HASHVAL, bHash, &dwHashLen, 0))
{
// Make a string version of the numeric digest value
csDigest.Empty();
CString tmp;
for (int i = 0; i<16; i++)
{
tmp.Format("%02x", bHash[i]);
csDigest+=tmp;
}

}
else csDigest=_T("Error getting hash param");

}
else csDigest=_T("Error hashing data");
}
else csDigest=_T("Error creating hash");

}
else csDigest=_T("Error acquiring context");


CryptDestroyHash(hHash);
CryptReleaseContext(hCryptProv, 0);
csBuffer.ReleaseBuffer();
return csDigest;


}

///////////////////////////////////////////////

#include "md5Capi.h"

void EncriptFunction(CString content)
{
Cmd5Capi md5Capi;

CString enc(content);

CString md5coad = md5Capi.Digest(enc);

AfxMessageBox(md5coad);

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900