c# - 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×tamp=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#.
解决方案
此 OpenSSL 命令正在计算在标准输入上传递给它的数据的 HMAC(即 echo 命令的输出)。HMAC 是一种消息验证码 (MAC),用于验证消息的完整性,即如果攻击者以任何方式修改消息,则 MAC 码将不再匹配(验证失败)。HMAC 将密钥与底层散列算法(在本例中为 SHA1)相结合以生成输出 MAC 值。
Microsoft 文档在此处提供了如何使用 SHA1 操作执行 HMAC 的完整示例:
推荐阅读
- node.js - 如何在同一控制器中以同一功能获取两个模型
- java - 如何在springboot中使用sleuth
- reactjs - 反应状态更新输入数据
- reactjs - 我对 reactjs 组件设计感到困惑
- javascript - 添加对现有网页的反应(旧版) - 导入不起作用
- c# - C# - 将 GridControl 绑定到 List 并在运行时操作记录
- c# - 在 C# 中将 Word docx 文件或 PDF 转换为位图
- api - 将令牌传递给 vuetable 发布请求 - http--Options
- c# - 如何在 c# 中使用 selenium 隐藏或禁用验证码
- properties - 如何使用 SPARQL 检索按使用排序的 Wikidata 的所有属性