【发布时间】:2014-09-20 19:06:09
【问题描述】:
我正在使用https://developer.linkedin.com/oauth-test-console 来确定我收到401 unauthorised 消息的原因。
由于某种原因,我的代码中生成的签名与此控制台上生成的签名不同。出于测试目的,代码中的nonce、timestamp 和baseString 与控制台中使用的值相同。然而签名仍然不匹配?
我正在使用以下代码生成签名:
HMACSHA1 hmacsha1 = new HMACSHA1();
hmacsha1.Key = Encoding.ASCII.GetBytes(string.Format("{0}&{1}", UrlEncode(), UrlEncode()));
string signature = Convert.ToBase64String(hashAlgorithm.ComputeHash(System.Text.Encoding.ASCII.GetBytes(baseString)));
UrlEncode() 和 UrlEncode() 分别是消费者密码和令牌密码,应用了 url 编码。
【问题讨论】: