Click here to Skip to main content
15,890,512 members
Articles / Desktop Programming / MFC
Article

Use Windows Crypto API to calculate a MD5 string.

Rate me:
Please Sign up or sign in to vote.
3.49/5 (29 votes)
29 Aug 2002 211.8K   6K   57   24
Use Windows Crypto API to calculate a MD5 string.

Introduction

The source code demonstrates how to invoke the Windows Crypto API to calculate a MD5 string.

The MD5 Message-Digest Algorithm is described in Internet RFC 132.

The sample uses the class Cmd5Capi, a very simple MFC class to wrap the standard win api necesary calls.

Includes required

#include <wincrypt.h> // Cryptographic API Prototypes and Definitions

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Spain Spain
Now, I works for Aurigae S.A a spanish services enterprise, specialized on information technologies for critical mission applications, mainly in the areas of payment system management, stock trading and telecommunications.

Comments and Discussions

 
GeneralThanks Pin
Asaf G6-May-08 0:05
Asaf G6-May-08 0:05 
QuestionHow to decrypt data? Pin
ivax4-Oct-05 0:49
ivax4-Oct-05 0:49 
AnswerRe: How to decrypt data? Pin
andyj11526-Oct-05 0:06
andyj11526-Oct-05 0:06 
GeneralA better solution : here is the code Pin
Elmue22-Apr-04 10:43
Elmue22-Apr-04 10:43 
GeneralRe: A better solution : here is the code Pin
HughJampton25-Apr-05 6:11
HughJampton25-Apr-05 6:11 
GeneralRe: A better solution : here is the code Pin
Anonymous25-Apr-05 12:32
Anonymous25-Apr-05 12:32 
GeneralRe: A better solution : here is the code Pin
HughJampton25-Apr-05 15:00
HughJampton25-Apr-05 15:00 
GeneralExcellent code - one simple modification Pin
Douglas R. Keesler5-Jun-05 15:41
Douglas R. Keesler5-Jun-05 15:41 
GeneralRe: A better solution : here is the code Pin
pscholl6-Jun-08 6:01
pscholl6-Jun-08 6:01 
GeneralRe: A better solution : here is the code Pin
Elmue6-Jun-08 14:40
Elmue6-Jun-08 14:40 
GeneralProblem with this constructor. Pin
Prakash Nadar20-Jan-04 16:28
Prakash Nadar20-Jan-04 16:28 
GeneralCompile Error ! Pin
freedem2-Dec-03 15:00
freedem2-Dec-03 15:00 
GeneralRe: Compile Error ! Pin
Victor M. Valenzuela2-Dec-03 21:28
Victor M. Valenzuela2-Dec-03 21:28 
GeneralRe: Compile Error ! Pin
Ștefan-Mihai MOGA29-Mar-06 20:44
professionalȘtefan-Mihai MOGA29-Mar-06 20:44 
GeneralRe: Compile Error ! Pin
bahram_cho6-Apr-07 20:42
bahram_cho6-Apr-07 20:42 
Generalcompilation Errors Pin
Rohit Gadagkar24-Sep-03 7:40
Rohit Gadagkar24-Sep-03 7:40 
GeneralRe: compilation Errors Pin
Vinayak16-Jun-04 9:54
Vinayak16-Jun-04 9:54 
GeneralRe: compilation Errors Pin
Scott B.21-Mar-06 18:59
Scott B.21-Mar-06 18:59 
GeneralDifferent Output Pin
tunafish245-Aug-03 16:42
tunafish245-Aug-03 16:42 
GeneralRe: Different Output Pin
qihongbo28-Sep-03 22:04
qihongbo28-Sep-03 22:04 
GeneralThanks Pin
Paul Hooper25-Apr-03 14:40
Paul Hooper25-Apr-03 14:40 
GeneralCrypto.h Pin
Anonymous4-Nov-02 3:15
Anonymous4-Nov-02 3:15 
GeneralRe: Crypto.h Pin
Ștefan-Mihai MOGA27-Jun-05 0:49
professionalȘtefan-Mihai MOGA27-Jun-05 0:49 
GeneralNeeds improvements Pin
Vagif Abilov30-Aug-02 2:46
professionalVagif Abilov30-Aug-02 2:46 
There are several improvements that both article and code need:

1. More careful code packaging. It's not enough to ZIP all files in the directory. You end up with some temporary files included in the package. Remember that the more compact is solution, the more elegant it looks. In your package there are about 200 KB of files included. However, 3 largest files (with extension NCB, OPT and APS) are intermediate files that occupy about 150 KB (75%!) of space and are not part of the project. You should examine source files before including them into a package.

2. Better C++ coding. Let's take as an example the following method:

CString &Cmd5Capi::Digest(CString & csBuffer)

Why is buffer declared as "CString&" and "const CString&" (or even "LPCTSTR")? It should not be modified by the method. The same goes for return value. Why is it "CString&" and not "const CString&"?

3. The method digest might as well be declared as static, so MD5 digest could be computed without allocating an instance of Cmd5Capi class.

However, it's a good attempt for a first article.

Best regards

Vagif Abilov
MCP (Visual C++)
Oslo, Norway


If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them.
Jack Handey, Deep Thoughts

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.