Tech Support > Operating Systems > Linux / Variants > Scripting with md5
Scripting with md5
Posted by Bob Richards on December 2nd, 2003


Hi there,

I need to write a shell script that will perform the equivalent of the
following javascript code:

hash = binl2hex(core_hmac_md5(key, word));

where key and word are strings.

As far as I know, I don't have a command line javascript interpreter and
it seems overkill to install one just for one line of code (also, I need
the result to be quite portable).

Is there anyway of doing the equivalent of the above in a shell script
or a C or Perl program? I'm not really sure of what the above does
(from code written by someone who has since left the company).

Thank you very much for any help you can offer in this matter,

Kind regards,

Bob

Posted by tigervamp on December 2nd, 2003


On Tue, 02 Dec 2003 05:52:38 -0500, Bob Richards wrote:

As far as what the code does, take a look at
http://pajhome.org.uk/crypt/md5/md5src.html which has the javascript
source to the functions you seem to be using.

As far as implementing this in perl, there is a module (among many of this
type) available at CPAN called Digest::HMAC_MD5. You can find it here:
http://search.cpan.org/~gaas/Digest-...st/HMAC_MD5.pm

Source for C functions implementing this aren't too difficult to find
either. You can find one such implementation (which I have not used)
licensed under the Lesser GPL here:
http://people.redhat.com/jbj/beecryp...8c-source.html

Let me know if this doesn't help,

Rob Gamble

Posted by Andy Baxter on December 3rd, 2003


At earth time Tue, 02 Dec 2003 10:52:38 +0000, the following transmission
was received from the entity known as Bob Richards:

In shell script, install the program md5sum, then do either:

result=`echo $var | md5sum | cut -c-32`

to md5sum a variable, or

result=`md5sum $file | cut -c-32`

to md5sum a file.

andy.

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.


Posted by tigervamp on December 3rd, 2003


On Wed, 03 Dec 2003 12:50:19 -0500, Andy Baxter wrote:

Looks like he needs to create an keyed hash, not just the digest that
md5sum will provide.

Rob Gamble


Similar Posts