Click here to Skip to main content
15,890,282 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 
This is an excellent piece of code, but it has a problem with VS2008 Beta.
With a Unicode build, the following line
HANDLE h_File = CreateFile(s8_Path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
gives me the following error:
error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

What is the correct syntax to avoid this error? I don't feel confident to experiment myself.

Likewise, with a non-unicode build I get the following warnings:
warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

I would prefer not to disable the warnings, so if someone could tell me how to code this correctly so that it works with all builds in both VC6 and VS2008 I would very much appreciate it.

Thanks
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 

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.