Есть идеи?
Вот код php
Код: Выделить всё
$data = array();
$data['kr-hash'] = '781abb2965bed3239bd81befdab05770c9698fae1d78f1c65dc466ecf3a28421';
$data['kr-answer'] = '{"shopId":"123456"}';
checkHash($data, 'testpassword_123456789pkLbGmKW');
function checkHash($data, $key)
{
$kr_answer = $data['kr-answer'];
$hash = hash_hmac('sha256', $kr_answer, $key);
echo 'hash = ' . $hash;
return ($hash == $data['kr-hash']);
Код: Выделить всё
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"]);
}
TIA
Подробнее здесь: https://stackoverflow.com/questions/790 ... sharp-net8