Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-30-2004, 07:21 PM   #1
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
Create a hash with any data

Hi, i would want to know how to create a hash of a data.

I've already know crypt() and how to create a md5 hash with it, but problems come when any byte is equal to zero, because de crypt function declaration is:

char * crypt(const char * key , const char *salt);


struct data{
int x;
int y;
int z;

struct data var1;
var1.x = 5;
var1.y = 0;
var1.z = 5;

hash = crypt((char *) &var1, "$1$");
/*the hash is: (for example) $1$ZH$YGGYInw6oH0P29Ze6hlo.1

again, with different data, (pay attention to var2.z)


struct data var2;
var2.x = 5;
var2.y = 0;
var2.z = 115;

hash = crypt((char *) &var2, "$1$");

/*the hash will be the same, since var2.z parameter which is different from first, is not passed, because var2.y is null-byte, and the string ends */

Could anybody show me another function to create a hash which i can pass null-byte data??

Thanks In Advance
Old 07-30-2004, 09:31 PM   #2
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Yeah, it looks like crypt() was intended for use with ASCII passwords, so a null value isn't really possible. Check out mhash. Haven't used it, but it looks something like what you want.
Old 07-31-2004, 03:13 AM   #3
Registered: Jan 2004
Location: Manitoba, Canada
Distribution: Debian
Posts: 454

Rep: Reputation: 32
If you just need a simple, quick and dirty hash, you can add or xor the bytes.
Old 07-31-2004, 09:15 AM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Does this help?
"man 3 sha" or "man md5"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Create MD5 hash from string trouby Linux - General 9 02-07-2012 08:08 PM
get my data back after mdadm --create RicoCarmen Linux - General 1 10-23-2005 08:18 PM
Create ISO files from audio, data and video cds Bateman Linux - General 4 06-19-2005 04:02 AM
Cannot mount CD-R to create a backup data CD ccin1492 Linux - Hardware 8 11-24-2004 02:15 PM
how to create a partition for swapping data between win2000pro and red hat 9.0? Mephisto3285 Linux - Newbie 3 07-04-2003 06:11 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:09 PM.

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