本文整理汇总了Python中Crypto.Hash方法的典型用法代码示例。如果您正苦于以下问题:Python Crypto.Hash方法的具体用法?Python Crypto.Hash怎么用?Python Crypto.Hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto
的用法示例。
在下文中一共展示了Crypto.Hash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Crypto [as 别名]
# 或者: from Crypto import Hash [as 别名]
def __init__(self):
self.client_write_MAC_key = None
self.server_write_MAC_key= None
self.client_write_key = None
self.server_write_key = None
self.client_write_IV = None
self.server_write_IV = None
self.mac_key_length = 160/8
self.enc_key_length = 128/8
self.fixed_iv_length = 16
self.premaster_secret = None
self.prf =TLSPRF(Crypto.Hash.SHA256)
示例2: runTest
# 需要导入模块: import Crypto [as 别名]
# 或者: from Crypto import Hash [as 别名]
def runTest(self):
h = self.hashmod.new(**self.extra_params)
h.update(self.input)
out1 = binascii.b2a_hex(h.digest())
out2 = h.hexdigest()
h = self.hashmod.new(self.input, **self.extra_params)
out3 = h.hexdigest()
out4 = binascii.b2a_hex(h.digest())
# PY3K: hexdigest() should return str(), and digest() bytes
self.assertEqual(self.expected, out1) # h = .new(); h.update(data); h.digest()
if sys.version_info[0] == 2:
self.assertEqual(self.expected, out2) # h = .new(); h.update(data); h.hexdigest()
self.assertEqual(self.expected, out3) # h = .new(data); h.hexdigest()
else:
self.assertEqual(self.expected.decode(), out2) # h = .new(); h.update(data); h.hexdigest()
self.assertEqual(self.expected.decode(), out3) # h = .new(data); h.hexdigest()
self.assertEqual(self.expected, out4) # h = .new(data); h.digest()
# Verify that the .new() method produces a fresh hash object, except
# for MD5 and SHA1, which are hashlib objects. (But test any .new()
# method that does exist.)
if self.hashmod.__name__ not in ('Crypto.Hash.MD5', 'Crypto.Hash.SHA1') or hasattr(h, 'new'):
h2 = h.new()
h2.update(self.input)
out5 = binascii.b2a_hex(h2.digest())
self.assertEqual(self.expected, out5)