using System;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
var dico = new Dictionary();
dico["kr-hash"]="781abb2965bed3239bd81befdab05770c9698fae1d78f1c65dc466ecf3a28421";
dico["kr-answer"] = "{\"shopId\":\"123456\"}";
checkHash(dico, "testpassword_123456789pkLbGmKW");
}
private static bool checkHash(Dictionary dico, string sKey){
var key= Encoding.UTF8.GetBytes(sKey);
var message = Encoding.UTF8.GetBytes(dico["kr-answer"]);
var hashmac = new HMACSHA256(key);
var hashmessage = hashmac.ComputeHash(message);
var hash = Convert.ToBase64String(hashmessage);
Console.WriteLine("hash = "+ hash);
return hash.Equals(dico["kr-hash"]);
}
Я пытаюсь преобразовать код php в код C#, но не могу найти тот же результат. Есть идеи? Вот код php[code]$data = array(); $data['kr-hash'] = '781abb2965bed3239bd81befdab05770c9698fae1d78f1c65dc466ecf3a28421'; $data['kr-answer'] = '{"shopId":"123456"}';
и вот код C#: [code]using System; using System.Text; using System.Collections.Generic; using System.Security.Cryptography;
public class Program { public static void Main() { var dico = new Dictionary(); dico["kr-hash"]="781abb2965bed3239bd81befdab05770c9698fae1d78f1c65dc466ecf3a28421"; dico["kr-answer"] = "{\"shopId\":\"123456\"}";