-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhmac-sha1
executable file
·37 lines (29 loc) · 905 Bytes
/
hmac-sha1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl
# This perl script computes the HMAC-SHA1 signature of the provided 'data'
# with the provided 'key'.
use strict;
use English;
use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex);
use MIME::Base64;
use CGI;
print "Content-type: application/xml\n\n";
my $cgi = new CGI;
my $key = $cgi->param('key');
my $data = $cgi->param('data');
my $digest = hmac_sha1($data, $key);
my $encoded = encode_base64($digest);
chop $encoded; # don't want the newline
my $hex = hmac_sha1_hex($data, $key);
print "<digest method='hmac-sha1' encoding='base64'>\n";
print "<key>", escape($key), "</key>\n";
print "<data>", escape($data), "</data>\n";
print "<hashb64>$encoded</hashb64>\n";
print "<hashhex>$hex</hashhex>\n";
print "</digest>\n";
# ----------------------------------------------------------------------
sub escape {
local $_ = shift;
s/&/&/sg;
s/</</sg;
return $_;
}