I'm creating Windows Phone 8.1 Store App with ability to upload some blobs into Azure Storage. I cannot use WindowsAzure.Storage lib (very weird), so I'm trying to use REST. I cannot figure out, what's wrong.
try
{
string time = DateTime.Now.ToString("R", System.Globalization.CultureInfo.InvariantCulture);
string tosign = "GET\n" +
"\n" + //Content-Encoding
"\n" + //Content-Language
"0\n" + //Content-Length
"\n" + //Content-MD5
"\n" + //Content-Type
"\n" + //Date
"\n" + //If-modified-since
"\n" + //If-match
"\n" + //If-none-match
"\n" + //If-unmodified-since
"\n" + //Range
"x-ms-date:" + time + "\nx-ms-version:2015-02-21\n" + //CanonicalizedHeaders
"/storage_name/\ncomp:list"; //CanonicalizedResource
string hashKey = "DHpNuYG5MXhamfbKmFPClUlNi38QiM2uqIqz07pgvpv2gmXJRwxaMlcV05pFCYsrelGYKPed9QphyJ/YnUrh5w=="; //Primary access key
MacAlgorithmProvider macAlgorithmProvider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha256);
var messageBuffer = CryptographicBuffer.ConvertStringToBinary(tosign, BinaryStringEncoding.Utf8);
IBuffer keyBuffer = CryptographicBuffer.ConvertStringToBinary(hashKey, BinaryStringEncoding.Utf8);
CryptographicKey hmacKey = macAlgorithmProvider.CreateKey(keyBuffer);
IBuffer signedMessage = CryptographicEngine.Sign(hmacKey, messageBuffer);
string hashedString = CryptographicBuffer.EncodeToBase64String(signedMessage);
var client = new HttpClient();
Uri uri = new Uri("https://storage_name.blob.core.windows.net/?comp=list");
client.DefaultRequestHeaders.Add("x-ms-date", time);
client.DefaultRequestHeaders.Add("x-ms-version", "2015-02-21");
client.DefaultRequestHeaders.Add("Authorization", "SharedKey storage_name:" + hashedString);
var response = await client.GetAsync(uri);
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
Error: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
How I can make it work?