openssl hmacsha256
时间: 2023-10-11 13:05:18 浏览: 74
OpenSSL is a widely used cryptographic library that provides various functions and utilities for handling encryption, decryption, and authentication. One of the functions provided by OpenSSL is HMAC-SHA256, which is a message authentication code (MAC) algorithm that uses the SHA-256 hash function.
To generate an HMAC-SHA256 hash using OpenSSL, you can use the following command:
```
openssl dgst -sha256 -hmac "key" file.txt
```
Here, "key" is the secret key used to generate the HMAC (in this example, we are using the string "key" as the key). "file.txt" is the file that you want to generate the HMAC for.
Alternatively, you can use the following command to generate an HMAC-SHA256 hash using a binary key:
```
openssl dgst -sha256 -hmac <keyfile.bin> file.txt
```
Here, "<keyfile.bin>" is the path to the binary key file.
By default, OpenSSL will output the HMAC-SHA256 hash as a hexadecimal string. If you want to output the hash in binary format, you can use the "-binary" option:
```
openssl dgst -sha256 -hmac "key" -binary file.txt
```
This will output the HMAC-SHA256 hash as a binary string.
阅读全文