【发布时间】:2020-10-24 19:11:27
【问题描述】:
随附的 Python 代码接收输入字符串(例如,用户密码)的哈希函数,并使用 MD5 生成 156 位哈希。此代码中可能存在哪些使密码哈希不适用的漏洞。
#
from Crypto.Hash import MD5
import binascii
def hash(msg):
# pad message to 16 bytes
if len(msg) < 16:
msg = msg + (16 - len(msg)) * 'A'
# pick first 16 bytes
msg = msg[:16]
# converts message to upper case
msg = msg.upper()
# create MD5 objects
h1 = MD5.new()
h2 = MD5.new()
# hash two parts of message separately
h1.update(msg[:8])
h2.update(msg[8:16])
# concatenate the two hashes
h = h1.digest() + h2.digest()
return h
# print message
print(binascii.hexlify(hash("Hello, this is a great passphrase, and I am
wondering if anyone can crack it")))
【问题讨论】:
标签: security md5 password-hash