本文整理匯總了Python中Cryptodome.Hash.SHA256屬性的典型用法代碼示例。如果您正苦於以下問題:Python Hash.SHA256屬性的具體用法?Python Hash.SHA256怎麽用?Python Hash.SHA256使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類Cryptodome.Hash
的用法示例。
在下文中一共展示了Hash.SHA256屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test2
# 需要導入模塊: from Cryptodome import Hash [as 別名]
# 或者: from Cryptodome.Hash import SHA256 [as 別名]
def test2(self):
"""From draft-josefsson-scrypt-kdf-01, Chapter 10"""
output_1 = t2b("""
55 ac 04 6e 56 e3 08 9f ec 16 91 c2 25 44 b6 05
f9 41 85 21 6d de 04 65 e6 8b 9d 57 c2 0d ac bc
49 ca 9c cc f1 79 b6 45 99 16 64 b3 9d 77 ef 31
7c 71 b8 45 b1 e3 0b d5 09 11 20 41 d3 a1 97 83
""")
output_2 = t2b("""
4d dc d8 f6 0b 98 be 21 83 0c ee 5e f2 27 01 f9
64 1a 44 18 d0 4c 04 14 ae ff 08 87 6b 34 ab 56
a1 d4 25 a1 22 58 33 54 9a db 84 1b 51 c9 b3 17
6a 27 2b de bb a1 d0 78 47 8f 62 b3 97 f3 3c 8d
""")
prf_hmac_sha256 = lambda p, s: HMAC.new(p, s, SHA256).digest()
output = PBKDF2(b("passwd"), b("salt"), 64, 1, prf=prf_hmac_sha256)
self.assertEqual(output, output_1)
output = PBKDF2(b("Password"), b("NaCl"), 64, 80000, prf=prf_hmac_sha256)
self.assertEqual(output, output_2)
示例2: testEncryptDecrypt2
# 需要導入模塊: from Cryptodome import Hash [as 別名]
# 或者: from Cryptodome.Hash import SHA256 [as 別名]
def testEncryptDecrypt2(self):
# Helper function to monitor what's requested from RNG
global asked
def localRng(N):
global asked
asked += N
return self.rng(N)
# Verify that OAEP is friendly to all hashes
for hashmod in (MD2,MD5,SHA1,SHA256,RIPEMD160):
# Verify that encrypt() asks for as many random bytes
# as the hash output size
asked = 0
pt = self.rng(40)
cipher = PKCS.new(self.key1024, hashmod, randfunc=localRng)
ct = cipher.encrypt(pt)
self.assertEqual(cipher.decrypt(ct), pt)
self.assertEqual(asked, hashmod.digest_size)
示例3: calculateChecksum
# 需要導入模塊: from Cryptodome import Hash [as 別名]
# 或者: from Cryptodome.Hash import SHA256 [as 別名]
def calculateChecksum(data):
"""The function used to calculate CIC checksums for xpd files"""
return HMAC.new(constants.cicKey, data, SHA256).hexdigest()
示例4: sign
# 需要導入模塊: from Cryptodome import Hash [as 別名]
# 或者: from Cryptodome.Hash import SHA256 [as 別名]
def sign(self, message):
"""Sign a message"""
return base64.standard_b64encode(
HMAC.new(self.sign_key, message.encode('utf-8'), SHA256).digest()).decode('utf-8')
示例5: sign
# 需要導入模塊: from Cryptodome import Hash [as 別名]
# 或者: from Cryptodome.Hash import SHA256 [as 別名]
def sign(self, message):
return HMAC.new(self.sign_key, message, SHA256).digest()