gpt4 book ai didi

python - MD5 key 加密

转载 作者:行者123 更新时间:2023-12-01 04:44:39 24 4
gpt4 key购买 nike

我正在尝试使用 MD5 算法对 txt 文件进行哈希处理,问题是出于安全原因我想使用特殊 key 对文本文件进行哈希处理。其中的想法是让两台机器交换消息并使用 key 通过消息的 MD5 散列应用安全检查。并且没有人应该知道这个特定的 key 。

我的机器是基于 Linux (Debian OS) 的。我使用 python 作为编程语言。

我已经通过互联网进行了挖掘,我可以在 python 中找到一个 MD5 库,但它没有更改所使用的 key 的选项

#
import md5

import string

hash = md5.new()

hash.update("this is the text to be hashed")

value = hash.digest()

print hash.hexdigest()
#

我还尝试使用 Debian 标准库 MD5sum,但我仍然不知道如何更改用于创建哈希的 key 。

感谢任何人有任何想法,我无法使用任何在线工具,因为我想将这个 MD5 哈希包含在我的 python 程序中或至少使用标准 Debian 库。

除了 python 和标准 Linux 库之外,我无法使用任何 C# 或 php 或任何其他编程工具。

非常感谢

最佳答案

您可以使用 python 中的 hmac 模块对消息进行 key 哈希。更多信息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()

关于python - MD5 key 加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29768697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com