TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Girija Pugazhenthi
NA
98
4.7k
What is the Equivalent c# method for the php "hash_hmac()"?
Jan 19 2018 2:16 AM
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=
Reply
Answers (
1
)
Render different view in multiple tabs
How can we make separate login page for diff areas?