Hi!
PatrickPan2012
Just a very crude Perl thing (wouldn't even dare to call it a script), that I put together to understand how Authorization is working with SharedKeys.
This is in now way intended to be complete and only works if you're only supplying the required headers x-ms-version and x-ms-date
Just thought it might put some people on the right track..
BTW: Interesting fact: When your signature fails, the Server outputs exact the string it used to compute the HMAC... (can be seen when using curl -v)
First the perl script getSignature.pl
Unfortunately there is no perl in the code template selection, hope this is readable
#!/usr/bin/perl
use Digest::SHA qw( hmac_sha256_base64 );
use MIME::Base64;
use v5.14;
use utf8;
use strict;
my $key = "The_nice_Base64_access_key that you copied out from AZure Portal==";
## Take first cmdline argument as date
my $date= $ARGV[0];
#Second arg: Storage Account Name
my $storageAccountName = lc($ARGV[1]);
#Third: BlobPath
my $blobPath = lc($ARGV[2]);
## Mind the number of newlines below, they're important
my $string_to_sign =
"GET
x-ms-date:$date
x-ms-version:2015-02-21
/".$storageAccountName.$blobPath;
## Uncomment to see whats going into the signature and run stand-alone with proper args
###print $string_to_sign;
my $signature = hmac_sha256_base64( $string_to_sign, decode_base64( $key ) );
$signature .= '=' x ( 4 - ( length( $signature ) % 4 ) );
say $signature;
And if you want to test it out using curl, another equally crude bash-script:
#/bin/bash
DATE=$(date -u "+%a, %d %b %Y %T GMT")
BLOBPATH="/folder/yetanotherfolder/image.jpg"
STORAGEACCOUNTNAME="your-storage-accountName"
echo $DATE
SIG=$(perl getSignature.pl "$DATE" "$STORAGEACCOUNTNAME" "$BLOBPATH")
echo $SIG
## See headers and response in case of errors
curl -v -H "Authorization: SharedKey $STORAGEACCOUNTNAME:$SIG" -H "x-ms-date: $DATE" -H "x-ms-version: 2015-02-21" https://$STORAGEACCOUNTNAME.blob.core.windows.net$BLOBPATH
##Download to file
#curl -H "Authorization: SharedKey $STORAGEACCOUNTNAME:$SIG" -H "x-ms-date: $DATE" -H "x-ms-version: 2015-02-21" https://$STORAGEACCOUNTNAME.blob.core.windows.net$BLOBPATH -o out.jpg