I need to convert the following php code in C#:
$res = mac256($ent, $key);
$result = encodeBase64($res);
where
function enc
This code should do the trick:
static byte[] hmacSHA256(String data, String key)
{
using (HMACSHA256 hmac = new HMACSHA256(Encoding.ASCII.GetBytes(key)))
{
return hmac.ComputeHash(Encoding.ASCII.GetBytes(data));
}
}
If I call this code:
Console.WriteLine(BitConverter.ToString(hmacSHA256("1234", "1234")).Replace("-", "").ToLower());
It returns:
4e4feaea959d426155a480dc07ef92f4754ee93edbe56d993d74f131497e66fb
When I run this in PHP:
echo hash_hmac('sha256', "1234", "1234", false);
It returns
4e4feaea959d426155a480dc07ef92f4754ee93edbe56d993d74f131497e66fb