简体   繁体   English

Linux-使用文件中的密钥进行openssl sha256

[英]Linux - openssl sha256 using key from file

I have a 32 byte key stored in a file called test_key.key 我有一个32字节的密钥存储在一个名为test_key.key的文件中

I wish to use openssl to create hash of a different file called mytext.txt. 我希望使用openssl创建另一个名为mytext.txt的文件的哈希。 I need to create the hash using HMAC-SHA-256 & the key in test_key.key 我需要使用HMAC-SHA-256和test_key.key中的密钥创建哈希

I thought I had it working with the following command: 我以为可以使用以下命令进行操作:

openssl dgst -sha256 -hmac $test_key.key mytext.txt

However, on closer examination I noticed it was using the string "test_key.key", not the actual file contents. 但是,在仔细检查后,我发现它使用的是字符串“ test_key.key”,而不是实际的文件内容。 I have tried a few different variations of this for the key file such as: 我为密钥文件尝试了一些不同的变体,例如:

"$test_key.key"
'$test_key.key'
/test_key.key

Sadly, they all seem to have the same problem. 可悲的是,它们似乎都存在相同的问题。

Can anyone advise me on this? 有人可以建议我吗? I wish to keep this as a one line command if possible. 我希望尽可能将其保留为一行命令。

openssl dgst -sha256 -hmac $(<test_key.key) mytext.txt 

(提供给用户David C. Rankin)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM