【发布时间】:2018-02-28 22:05:57
【问题描述】:
当我遇到这段 Python 代码时,我正在学习密码学的基础知识
if self.shared_hash != None:
h = HMAC.new(self.shared_hash)
hmac = data[:h.digest_size*2] #Get the HMAC part of the message
data = data[h.digest_size*2:] # Get the data part of the message
h.update(data)
if h.hexdigest() != str(hmac, 'ascii'): #HMAC is not right, so raise an error
if self.verbose:
print("Bad message")
print("HMAC from message:",str(hmac,'ascii'))
print("HMAC from digest:",h.hexdigest())
print("Not verifying message:",data)
raise RuntimeError("Bad message: HMAC does not match")
由于 HMAC 是检查消息的真实性,我了解检查 HMAC 的重要性。但是为什么我们要比较消息中的 HMAC 和摘要中的 HMAC。此外,摘要中的 HMAC 是什么?它只是消息的哈希值吗?
【问题讨论】:
标签: python cryptography hmac digest