LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2010, 04:58 AM   #1
aa.bb.cc
LQ Newbie
 
Registered: Jul 2010
Posts: 10

Rep: Reputation: 0
Unhappy md5 checksum of a string


hello everyone

can anybody help me to get a code in c++ to find the md5 checksum of a string.
thanks in advance
 
Old 07-16-2010, 05:25 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Is there a C library on your system?
have you tried man -k md5?

on my BSD I have this:
Code:
     #include <sys/types.h>
     #include <sys/md5.h>

     void
     MD5Init(MD5_CTX *buf);

     void
     MD5Transform(u_int32_t buf[4], const unsigned char block[64]);
also
http://sourceforge.net/projects/libmd5-rfc/

google for RFC1321

Last edited by bigearsbilly; 07-16-2010 at 05:27 AM.
 
1 members found this post helpful.
Old 07-16-2010, 06:07 AM   #3
aa.bb.cc
LQ Newbie
 
Registered: Jul 2010
Posts: 10

Original Poster
Rep: Reputation: 0
hey...
thankyou so much. i just want to know one more thing.what is the use of the parameter const unsigned char block[64]. i mean what will i send in the argument.
 
Old 07-16-2010, 08:11 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
this works for me on FreeBSD.

(you need to specify the md5 library to link)
export LDLIBS=-lmd

Code:
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <md5.h>

int main(int argc, char * argv) {

    const char * p = "hello\n";
    char buffer[512];
    MD5Data((void *) p,  strlen(p), buffer);
    puts(buffer);

    return 0;
}
Code:
$ ./md5           
b1946ac92492d2347c6235b4d2611184
$ echo hello | md5
b1946ac92492d2347c6235b4d2611184
no error checking, no warranty

Last edited by bigearsbilly; 07-16-2010 at 08:13 AM. Reason: tidied up
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
md5 checksum manz00r Slackware 14 06-30-2008 09:47 AM
Is MD5 Checksum enough? tededlin Linux - Newbie 2 08-02-2006 11:27 PM
MD5 Checksum hitest Mandriva 7 05-21-2005 06:06 PM
Md5 Checksum dna9 Linux - Newbie 2 12-18-2004 11:11 PM
MD5 Checksum codedv Linux - Distributions 5 12-07-2003 08:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration