jeudi 29 janvier 2015

AWS signature for signed URL

I came across a .NET example on how to get a signature needed for signing aws request api calls.


I am working on a windows phone 8 app and got stuck with the line



KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);


It appears that windows phone 8 does not have the Create method, the error is below:



'System.Security.Cryptography.KeyedHashAlgorithm' does not contain a definition for Create



Is there an alternative way around this?


Here is the complete code snippet



public static byte[] HmacSHA256(String data, byte[] key)
{
String algorithm = "HmacSHA256";
KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);
kha.Key = key;

return kha.ComputeHash(Encoding.UTF8.GetBytes(data));
}



static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName)
{
byte[] kSecret = Encoding.UTF8.GetBytes(("AWS4" + key).ToCharArray());
byte[] kDate = HmacSHA256(dateStamp, kSecret);
byte[] kRegion = HmacSHA256(regionName, kDate);
byte[] kService = HmacSHA256(serviceName, kRegion);
byte[] kSigning = HmacSHA256("aws4_request", kService);

return kSigning;
}




Aucun commentaire:

Enregistrer un commentaire