I have a sample code in php.I need to implement this in c#.I tried the following but I am getting different values in both.
Please suggest me an exact hash method in c#.
php code:
- $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);
- }
signature: ZToYIGWks4dBLImEKWozVZTkxZc=
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);
- }
signature: wR/E2jbMo9Y87aqXllcZAynCyRE=