Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
What is the Equivalent c# method for the php "hash_hmac()"?
Girija Pugazhenthi
Jan 19 2018 2:16 AM
105
Reply
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=
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Render different view in multiple tabs
How can we make separate login page for diff areas?