我正在尝试使用MD5算法散列一个txt文件,问题是出于安全原因,我想使用一个特殊的密钥来散列文本文件。其中的想法是让两台机器交换消息,并使用密钥通过消息的MD5散列应用安全检查。任何人都不应该知道这个特定的密钥。
我的机器是基于Linux (Debian OS)的。我正在使用python作为编程语言。
我已经在互联网上找到了python的MD5库,但它不能更改所使用的密钥
import md5
import string
hash = md5.new()
hash.update("this is the text to be hashed")
value = hash.digest()
print hash.hexdigest()我也尝试过使用Debian标准库MD5sum,但我仍然不知道如何更改用于创建散列的键。
感谢任何人有任何想法,我不能使用任何在线工具,因为我想在我的python程序中包含这个MD5散列,或者至少使用标准的Debian库。
除了python和标准linux库之外,我不能使用任何C#或php或任何其他编程工具。
非常感谢
发布于 2015-04-21 18:34:11
您可以使用python中的hmac模块对消息进行密钥散列。更多信息here。
下面是一个示例程序:
import hmac
import md5
hash_key = 'secret hashing key'
hash = hmac.new(hash_key, 'this is the text to be hashed', md5)
value = hash.digest()
print hash.hexdigest()发布于 2015-04-22 15:16:34
非常感谢你的反馈和回答,我找到了一种称为HMAC (散列消息认证码)的密钥认证方法,它
echo值‘-n’| openssl dgst -md5密钥‘-hmac’
(stdin)= 01433efd5f16327ea4b31144572c67f6
有关更多信息,请参考openssl库
openssl dgst -md5|-md4|-md2|-sha1|-sha|-mdc2|-ripemd160|-dss1 -d -binary -sign文件名-passin参数-prverify文件名-hmac密钥md5|md4|md2|sha1|sha|mdc2|ripemd160 -d
其中密钥鉴权说明如下:
MAC :使用key创建一个哈希-hmac。
MAC alg:创建-mac (键控消息认证码)。
目前最流行的MAC算法是HMAC ( hash -based MAC ),但也有一些不是基于hash的MAC算法,例如ccgost引擎支持的gost-mac算法。应通过-macopt参数设置MAC密钥和其他选项。
作为参考,我使用了以下博客和MD5手册页
http://nwsmith.blogspot.com/2012/07/using-openssl-to-generate-hmac-using.html
http://linux.die.net/man/1/md5
https://stackoverflow.com/questions/29768697
复制相似问题