Hash-based Authentication Message Code or HMAC is used to authenticate message with hash functions. Message authentication is important mechanism in cyber security and used to check message authenticity. There are different ways and mechanisms for Message Authentication.

基于哈希的身份验证消息代码或HMAC用于通过哈希功能对消息进行身份验证。 消息身份验证是网络安全中的重要机制,用于检查消息的真实性。 消息认证有不同的方式和机制。

信息 (Message)

Message is the data, text, image or whatever else we want to authenticate. Message is checked against it authenticity with given key by hashing them.

消息是数据,文本,图像或我们要验证的任何其他内容。 通过散列消息,使用给定的密钥检查消息的真实性。

(Key)

Key is used to known by two sides to check authenticity of the message. As stated previously Message and key added together and hash value is calculated.

双方都使用密钥来检查消息的真实性。 如前所述,消息和密钥加在一起并计算哈希值。

散列函数 (Hash Function)

Hash function is used to calculate hash value which is unique for give KEY+MESSAGE. Hash function can be sha1 , sha256 or another one.

哈希函数用于计算哈希值,这对于给定KEY + MESSAGE是唯一的。 哈希函数可以是sha1sha256或另一个。

使用OpenSSL创建HMAC (Create HMAC with OpenSSL)

We can use OpenSSL tool inorder to create some HMAC value or hash. We will use echo and openssl commands. We will use sha256 as hash function. We will provide data or message we want to HMAC and then hash it with -hmac and key mysecretkey like below.

我们可以使用OpenSSL工具来创建一些HMAC值或哈希。 我们将使用echoopenssl命令。 我们将使用sha256作为哈希函数。 我们将向HMAC提供所需的数据或消息,然后使用-hmac和密钥mysecretkey对其进行散列,如下所示。

$ echo -n "secretmessage.txt" | openssl dgst -sha256 -hmac "mysecretkey"
Create HMAC with OpenSSL
Create HMAC with OpenSSL
使用OpenSSL创建HMAC
LEARN MORE  What Is Windows Sysinternal?
了解更多什么是Windows Sysinternal?

翻译自: https://www.poftut.com/hmac-hach-based-message-authentication-code-tutorial/

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐