【发布时间】:2015-06-08 06:50:08
【问题描述】:
我已经搜索了几天了,这个 azure auth 正在杀死我。我不断收到标题中的错误。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace netTest
{
class Program
{
static void Main(string[] args)
{
var b = new bt();
b.GetBlob_Test();
Console.ReadLine();
}
public class bt
{
string accessKey = "4LVWlzPCPA5k45VDAPJJU6zXK6KvycT142Z8owbQv1m8bPm+cZPQamDKne/Uq4BHjAb9QR8bpanvoIgyOydcOg==";
string accountName = "trikegirlstudio";
string container = "sgm";
// GetBlob_Test
public void GetBlob_Test()
{
Console.WriteLine("Attempting to GET from server");
DateTime dt = DateTime.UtcNow;
string stringToSign = String.Format("GET\n"
+ "\n" // content md5
+ "\n" // content type
+ "x-ms-date:" + dt.ToString("R") + "x-ms-version:2009-09-19\n" + "\n" // headers
+ "/{0}/{1}\ncomp:list\nrestype:container", accountName, container);
string authorizationKey = SignThis(stringToSign, accessKey, accountName);
string method = "GET";
string urlPath = string.Format("http://{0}.blob.core.windows.net/{1}?restype=container&comp=list", accountName, container);
Uri uriTest = new Uri(urlPath);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriTest);
request.Proxy = new WebProxy("127.0.0.1", 8888);
request.Method = method;
request.Headers.Add("x-ms-date", dt.ToString("R"));
request.Headers.Add("x-ms-version", "2009-09-19");
request.Headers.Add("Authorization", authorizationKey);
Console.WriteLine("Authorization: " + authorizationKey);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Console.WriteLine("Response = " + response);
}
}
private static String SignThis(String StringToSign, string Key, string Account)
{
//StringToSign =
String signature = string.Empty;
byte[] unicodeKey = Convert.FromBase64String(Key);
using (HMACSHA256 hmacSha256 = new HMACSHA256(unicodeKey))
{
Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(StringToSign);
signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
}
String authorizationHeader = String.Format(
CultureInfo.InvariantCulture,
"{0} {1}:{2}",
"SharedKeyLite",
Account,
signature);
Console.WriteLine(StringToSign);
return authorizationHeader;
}
}
}
}
任何帮助将不胜感激 我真的看不出哪里出了问题
编辑:: 完全错误
AuthenticationFailedServer 未能验证请求。确保 Authorization 标头的值正确形成,包括签名。
请求ID:a8098960-0001-0003-3d38-a2fc0d000000
时间:2015-06-08T22:14:39.9876002Z 在 HTTP 请求“kmOqr60n0Nus1HJ1xoaplISdTEk8Hfdj9BIJK74Ojow=”中找到的 MAC 签名与任何计算的签名都不相同。服务器使用以下字符串进行签名:'GET
x-ms-date:格林威治标准时间 2015 年 6 月 8 日星期一 22:14:41 x-ms-版本:2009-09-19 /trikegirlstudio/sgm?comp=list'。
【问题讨论】:
-
请添加错误信息