[H-GEN] md5sum generation

Jason Parker-Burlingham jasonp at panix.com
Mon Mar 27 10:14:30 EST 2006


On 3/26/06, Rick Phillips <rickp at suntech.net.au> wrote:
> > Either of these commands given to bash:
> >
> >   echo "password" | md5sum
> >   md5sum <<<"$password"
> >
> > will do it on a single line, if that is what you
> > want.
>
> Thanks Russell but these two lines don't give a result consistent with
> the database.
>
> If I create a text file with blahblah in it and run "md5sum textfile", I
> get 42d388f8b1db997faaf7dab487f11290
>
> If I run either of the other two examples, I get
> 7ec306b6fa01510ffc4e0d0fac97c23e (I assume the "$" above is a typo as
> this gives yet another result.

The $ is a directive to the shell to replace "$password" with the
value of the shell variabled named "password".

The first md5sum you have is the md5sum of the string "blahblah":

$ echo -n "blahblah" | md5sum
42d388f8b1db997faaf7dab487f11290  -

The second sum is the md5sum of the string "blahblah\n" where "\n" is
Unix for "newline", or ascii character 10:

$ echo -ne "blahblah\n"|md5sum
7ec306b6fa01510ffc4e0d0fac97c23e  -

So!  The solution is to programmatically generate files with newlines
and checksum those, if you like, or at the very least get a string
which is NOT terminated with a newline into md5sum, using the "echo -n
foo" approach listed above.

jason




More information about the General mailing list