本文整理汇总了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()