C# HMACSHA1 问题,请大家帮忙

2002pine 2014-07-09 12:34:56
我不会perl,我要做一个加密的程序。
请哪位高手帮我下,告诉我digest最后的值是多少

或者大家给我一个C#的 可以和下面同样值的函数



$challenge'='27c81c82d52252c2fd0567e859df3c31';
$key='xyzxyz';

$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();
}
...全文
118 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
save4me 2014-07-09
  • 打赏
  • 举报
回复
结果: c87dbf5a1dc648f5d3a4d61e806dafd1bb70cddf 代码在另外一个帖子回复了

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧