首页 > 解决方案 > Mimic linux openssl command in C#

问题描述

I have a linux command and I'm trying to figure out how to mimic it in C# to get what is expected but can't seem to get it. It has to do with hashing a url with a secret key. The linux command is (fake site and numbers just for example):

echo -n "http://example.com/deliver?id=8247653546577888776655553d323453-3h78-7y42-b3d7-8u4q111y5hr6&timestamp=1556034591" | openssl dgst -sha1 -hmac "567gy324-6666-4444-fr46-2h7arwdh5555"

I don't really know what the commands mean so not sure where to even start with how to try and get this kind of call in C#.

标签: c#linuxopenssl

解决方案


此 OpenSSL 命令正在计算在标准输入上传递给它的数据的 HMAC(即 echo 命令的输出)。HMAC 是一种消息验证码 (MAC),用于验证消息的完整性,即如果攻击者以任何方式修改消息,则 MAC 码将不再匹配(验证失败)。HMAC 将密钥与底层散列算法(在本例中为 SHA1)相结合以生成输出 MAC 值。

Microsoft 文档在此处提供了如何使用 SHA1 操作执行 HMAC 的完整示例:

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.hmacsha1?view=netframework-4.8


推荐阅读