Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compute md5 2

Status
Not open for further replies.

flubbard

Technical User
Jun 11, 2003
148
US
Does anyone know of a way to programmatically compute the md5 on a file from within c. I would like to use md5 as a hash to determine if the locally stored file matches a remote file but I am having trouble finding an example where the md5 is returned to the program.

Any help would be appreciated.
 
It might help if you specify your OS since you may already have the functionality available to you.

(Windoze by chance?!!)


Trojan.
 
OS is linux. I can call md5sum from the command line but i do not know how to get this value back into the program.
 
Try "man MD5"

md5(3) OpenSSL md5(3)

NAME
MD2, MD4, MD5, MD2_Init, MD2_Update, MD2_Final, MD4_Init, MD4_Update,
MD4_Final, MD5_Init, MD5_Update, MD5_Final - MD2, MD4, and MD5 hash
functions

SYNOPSIS
#include <openssl/md2.h>

unsigned char *MD2(const unsigned char *d, unsigned long n,
unsigned char *md);

void MD2_Init(MD2_CTX *c);
void MD2_Update(MD2_CTX *c, const unsigned char *data,
unsigned long len);
void MD2_Final(unsigned char *md, MD2_CTX *c);

#include <openssl/md4.h>

unsigned char *MD4(const unsigned char *d, unsigned long n,
unsigned char *md);

void MD4_Init(MD4_CTX *c);
void MD4_Update(MD4_CTX *c, const void *data,
unsigned long len);
void MD4_Final(unsigned char *md, MD4_CTX *c);

#include <openssl/md5.h>

unsigned char *MD5(const unsigned char *d, unsigned long n,
unsigned char *md);

void MD5_Init(MD5_CTX *c);
void MD5_Update(MD5_CTX *c, const void *data,
unsigned long len);
void MD5_Final(unsigned char *md, MD5_CTX *c);

DESCRIPTION
MD2, MD4, and MD5 are cryptographic hash functions with a 128 bit out-
put.

MD2(), MD4(), and MD5() compute the MD2, MD4, and MD5 message digest of
the n bytes at d and place it in md (which must have space for
MD2_DIGEST_LENGTH == MD4_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16 bytes
of output). If md is NULL, the digest is placed in a static array.



Trojan.
 
when attempting to use the MD5 function, I get an error: Undefined reference to 'MD5'. I have #include <openssl/md5.h> Do I need to include other compiler options?
 
It does not seem to work. I am trying g++ md5_test.c -lopenssl and I receive and error that the compiler can't find openssl. I do have a md5.h in my /usr/include/openssl directory.

Any other thoughts?
 
Seems to compile now. I'm still getting a different answer everytime it is run so I will have to take a look at that, but at least it is compiling.

Thanks for the help.
 
thanks to you both. I was able to use a combination of the two to get the result I was looking for. It seems to function now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top