Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an sample code in php.I need to implement this in c#.I tried the following code for generating signature using HMACSHA1 but I am getting an different values in c# and php code.

Please suggest me an exact hash method in c#.

php code:
PHP
<pre>$signature = $this->hexToBase64(hash_hmac("sha1", $string_to_sign, self::SECRET_KEY));  
   
private function hexToBase64($hex){  
$return = "";  
foreach(str_split($hex, 2) as $pair){  
$return .= chr(hexdec($pair));  
}  
return base64_encode($return);  
}  


Quote:
signature: ZToYIGWks4dBLImEKWozVZTkxZc=


What I have tried:

c# code:
var key = Encoding.UTF8.GetBytes(apiKey);  
string signature ;  
using (var hmac = new HMACSHA1(key))  
{  
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));  
signature = Convert.ToBase64String(hash);  
}  


Quote:
signature: wR/E2jbMo9Y87aqXllcZAynCyRE=
Posted
Updated 18-Jan-18 21:00pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900