using System.Text;
using System.Security.Cryptography;
public static string Hashage(string chaine, string cle)
{
Encoding encoding = Encoding.ASCII;
byte[] keyByte = PackH(cle);
HMACSHA512 hmacsha512 = new HMACSHA512(keyByte);
return ByteToString(hmacsha512.ComputeHash(encoding.GetBytes(chaine)));
}
private static byte[] PackH(string hex)
{
if ((hex.Length % 2) == 1) hex += ‘0’;
byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
private static string ByteToString(byte[] buff)
{
string sbinary = « »;
for (int i = 0; i < buff.Length; i++)
{
sbinary += buff[i].ToString(« X2 »); // hex format
}
return (sbinary);
}
Laisser un commentaire