300分求帮忙,请问C#怎么做 pack "H*"的效果, 请帮忙实现以下功能

2002pine 2002pine 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
不会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();
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
2002pine
C# 111,128 成员 642,537 内容