本文整理匯總了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)