How to write the follow simple sha1Hex(sbyte[] data, string key) in C#(.net) ?
下面是Java的代码,c#要怎么写这个简单的算法,要带key的。
public static string sha1Hex(sbyte[] data, string key)
{
sbyte[] keyBytes = key.GetBytes();
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac;
StringBuilder sb = new StringBuilder();
try
{
mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
sbyte[] rawHmac = mac.doFinal(data);
foreach (sbyte b in rawHmac)
{
sb.Append(byteToHexString(b));
}
}
catch (Exception)
{
}
return sb.ToString();
}
http://stackoverflow.com/a/6533030/2586541