Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use MIME::Base64 qw(encode_base64);
- use Digest::HMAC_SHA1;
- use String::Escape qw( printable unprintable );
- sub _ascii_to_hex {
- (my $str = shift) =~ s/(.|n)/sprintf("%02lx", ord $1)/eg;
- return $str;
- }
- sub _encode {
- my ( $aws_secret_access_key, $str ) = @_;
- print "secret key hex: "._ascii_to_hex($aws_secret_access_key)."n";
- my $hmac = Digest::HMAC_SHA1->new($aws_secret_access_key);
- $hmac->add($str);
- my $digest = $hmac->digest;
- print "cleartext hex: "._ascii_to_hex($str)."n";
- print "digest hex: "._ascii_to_hex($digest)."n";
- my $b64 = encode_base64( $digest, '' );
- print "encoded: ".$b64."n";
- }
- my $secret = "abcd1234";
- my $cleartext = "GETnnnFri, 12 Dec 2008 10:08:51 GMT+00:00n/";
- _encode($secret, $cleartext);
- $ ./testhmac.pl
- secret key hex: 6162636431323334
- cleartext hex: 4745540a0a0a4672692c2031322044656320323030382031303a30383a353120474d542b30303a30300a2f
- digest hex: 63308f9b8a198440d6d8685a3f3f70d0aab02f68
- encoded: YzCPm4oZhEDW2GhaPz9w0KqwL2g=
- $ s3ls --access-key=foobar --secret-key=abcd1234
- ...
- secret key hex: 6162636431323334
- cleartext hex: 4745540a0a0a4672692c2031322044656320323030382031303a30383a353120474d542b30303a30300a2f
- digest hex: c0da50050c451847de7ed055c5286de584527a22
- encoded: wNpQBQxFGEfeftBVxSht5YRSeiI=
- use Digest::SHA qw(hmac_sha1_hex);
- my $hash = hmac_sha1_hex($data, $key);
- secret key hex: abcd...1234
- _ascii_to_hex("blahblahblah")
Add Comment
Please, Sign In to add comment