ankoder.com에서 API를 테스트하고 authentication token의 다이제스트 계산에 문제가 있습니다. 내가 C#에서 전화하려고하는 동안 샘플은 루비입니다. HMAC-SHA1에서 다이제스트 결과를 비교할 때 암호 키 결과에 문제가 있습니다.ruby의 hmac-sha1이 C# HMACSHA1과 다릅니다
require 'hmac-sha1'
require 'digest/sha1'
require 'base64'
token="-Sat, 14 Nov 2009 09:47:53 GMT-GET-/video.xml-"
private_key="whatever"
salt=Digest::SHA1.hexdigest(token)[0..19]
passkey=Base64.encode64(HMAC::SHA1.digest(private_key, salt)).strip
나에게 결과를 제공합니다 :
여기 테스트하기 쉽도록하는 코드입니다 "X/0EngsTYf7L8e7LvoihTMLetlM = \ n" 나는 다음과 C#에서 이것을 시도하는 경우 :
const string PrivateKey = "whatever";
var date = "Sat, 14 Nov 2009 09:47:53 GMT";//DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss") + " GMT";
string token=string.Format("-{0}-GET-/video.xml-", date);
var salt_binary=SHA1.Create().ComputeHash(Encoding.ASCII.GetBytes(token));
var salt_hex=BitConverter.ToString(salt_binary).Replace("-", "").ToLower();
var salt =salt_hex.Substring(0,20);
var hmac_sha1 =
new HMACSHA1(Encoding.ASCII.GetBytes(salt));
hmac_sha1.Initialize();
var private_key_binary = Encoding.ASCII.GetBytes(PrivateKey);
var passkey_binary = hmac_sha1.ComputeHash(private_key_binary,0,private_key_binary.Length);
var passkey = Convert.ToBase64String(passkey_binary).Trim();
염 결과는 동일하지만, 암호 키 결과 different- C 번호 내게 제공된다
QLC68XjQlEBurwbVwr7euUfHW/K =
0,123,516을두 가지 모두 소금을 생성합니다. f5cab5092f9271d43d2e
좋은 아이디어 무슨 일이 일어 났습니까?
궁금한 점이 있다면 어떤 결과가 있습니까? – quantumpotato
X/0EngsTYf7L8e7LvoihTMLetlM = –