300分求帮忙,请问C#怎么做 pack "H*"的效果, 请帮忙实现以下功能
不会perl,我要做一个加密的程序。
或者大家给我一个C#的 请帮忙实现以下功能的
$challenge='27c81c82d52252c2fd0567e859df3c31';
$portal_secret=‘ABCD’;
$ascii_key = pack "H*", $portal_secret;
$login_params='res=success'+'&challenge=$challenge'
my $digest = `echo -n "$login_params" | openssl dgst -sha1 -hmac "$ascii_key"`;
$digest =~ s/[\n\r\s]+$//;
$digest= substr($digest,-40,40);
我用的是,可惜结果不样,请高手帮忙
public static string HashUTF8(string keyStr,string sourceStr)
{
byte[] key = System.Text.Encoding.UTF8.GetBytes(keyStr);
HMACSHA1 hmac = new HMACSHA1(key);
// Convert the input string to a byte array and compute the hash.
byte[] data = hmac.ComputeHash(Encoding.UTF8.GetBytes(sourceStr));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}