Click here to Skip to main content
15,909,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I have a PHP code i need to convert one part to c# anybody suggest me or any equivalent method available.If available please guide me.Kindly waiting for reply.
This is my PHP code part that need convert to be c#
PHP
$signature = rawurlencode(
	base64_encode(
		hash_hmac("sha1", $concatenatedString, $privateKey, true)
	)
);


Here i need $signature in a string c#.
I have $concatenatedString, $privateKey as a input.

Thanks & Regards
Ganesh
Posted
Updated 12-Sep-13 23:15pm
v2

Dear Ganesh,

I dont think that both this PHP and C# will work simultaneously in same project.

with regards,

Sunil
 
Share this answer
 
 
Share this answer
 
hi try something like this


C#
string signature = System.Security.Cryptography.FormsAuthentication.HashPasswordForStoringInConfigFile(concatenatedString;SHA1");



there is no need to convert it into base64 unless you want to store it in some readable form
 
Share this answer
 
v3
string secretkey = "CD45FF96D6752A4D";



C#
string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
        string sectoken = Convert.ToBase64String(Guid.NewGuid().ToByteArray());



var enc = Encoding.ASCII;
        HMACSHA256 hmac = new HMACSHA256(enc.GetBytes(secretkey));
        hmac.Initialize();

        byte[] buffer = enc.GetBytes(sectoken);
        string signature = BitConverter.ToString(hmac.ComputeHash(buffer)).Replace("-", "").ToLower();



change token and sectoken
 
Share this answer
 
I dont think that was difficult. Just change the syntax to C#. Here is the translated code

C#
string signature = rawurlencode(base64_encode(hash_hmac("sha1", concatenatedString, privateKey, true)));
 
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