我想使用rest api生成any()
令牌,我的api版本是SAS
所以here 像这样描述要签名的字符串
2017-07-29
但是在文档(在同一页面上)中也说,StringToSign = signedpermissions + "\n" +
signedstart + "\n" +
signedexpiry + "\n" +
canonicalizedresource + "\n" +
signedidentifier + "\n" +
signedIP + "\n" +
signedProtocol + "\n" +
signedversion + "\n" +
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct
参数是必需的,上述字符串中不存在该参数。我试图将signedresource
放在signedresource
之后
signedversion
我的完整功能是
StringToSign = signedpermissions + "\n" +
signedstart + "\n" +
signedexpiry + "\n" +
canonicalizedresource + "\n" +
signedidentifier + "\n" +
signedIP + "\n" +
signedProtocol + "\n" +
signedversion + "\n" +
signedResource + "\n"
rscc + "\n" +
rscd + "\n" +
rsce + "\n" +
rscl + "\n" +
rsct
然后我得到错误 public static string CreateSAS(DateTime signedStart , DateTime signedExpiry, string docAzureLocation)
{
string a = signedStart.ToString("yyyy-MM-dd");
string b = signedExpiry.ToString("yyyy-MM-dd");
string canonicalizedresource = "/blob" + docAzureLocation.Substring(7);
string stringToSign = "r\n" +
/*a +*/ "\n" +
b + "\n" +
canonicalizedresource + "\n" +
"\n" +
"\n" +
"\n" +
AzureApiVersion + "\n" +
"b\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"";
string signature;
using (var hmacSha256 = new HMACSHA256(Convert.FromBase64String(APP_SETTINGS.StorageKey)))
{
var dataToHmac = Encoding.UTF8.GetBytes(stringToSign);
signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
}
string query = string.Format("se={0}&sp=r&sv={1}&sr=b&sig={2}", b, AzureApiVersion, signature);
return query;
}
。
所以我的问题是如何生成正确的Signature fields not well formed
?