First public contribution.
2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 # This component and the accompanying materials are made available
5 # under the terms of the License "Eclipse Public License v1.0"
6 # which accompanies this distribution, and is available
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 # Initial Contributors:
10 # Nokia Corporation - initial contribution.
22 # HASH MD2/MD4/MD5/SHA1 Digest Generator
24 #----------Define Function Headers----------
27 use Digest::MD2 qw(md2 md2_hex md2_base64); # Copy-right 1998-2001 Gisle Aas.
28 use Digest::MD4; # Mike McCauley/Neil Winton/RSA Data Security
29 use Digest::MD5 qw(md5 md5_hex md5_base64); # Copy-right 1998-2002 Gisle Aas.
30 use Digest::SHA1 qw(sha1 sha1_hex sha1_base64); # Copy-right 1999-2001 Gisle Aas.
33 use Digest::HMAC_MD2 qw(hmac_md2 hmac_md2_hex);
35 use Digest::HMAC_MD5 qw(hmac_md5 hmac_md5_hex);
36 use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex);
38 #-------------- MAIN SCRIPT -----------------
41 GetOptions ('convfromhex' => \$convfromhex );
42 my $numArgs = $#ARGV + 1;
45 my $origkey = @ARGV[1];
47 print "key is: $origkey\n";
49 $key = pack("H*", $origkey);
50 print "Converting key from hex\n";
53 #print("Data to be Hashed: \n");
56 open(DATA, "< $file" ) or die "Can't open $file : $!";
67 #----------Return Hashed Values----------
71 substr($output,length($file)-4,length($file),"_HASHDATA.txt");
73 open(OUT, "> $output") or die "Can't open $output : $!";
75 print OUT "****** HASH MD2/MD4/MD5/SHA1 ******\n";
79 print OUT md2_hex($data);
83 print OUT Digest::MD4->hexhash($data);
87 print OUT md5_hex($data);
91 print OUT sha1_hex($data);
95 print OUT "****** HMAC MD2/MD4/MD5/SHA1 ******\n";
98 print OUT "HMAC-MD2: ";
99 print OUT hmac_md2_hex($data, $key);
102 my $hmac = Digest::HMAC_MD4->new($key);
105 print OUT "HMAC-MD4: ";
106 print OUT $hmac->hexdigest;
109 print OUT "HMAC-MD5: ";
110 print OUT hmac_md5_hex($data, $key);
113 print OUT "HMAC-SHA1: ";
114 print OUT hmac_sha1_hex($data, $key);