本文整理匯總了Python中hashlib.sha512方法的典型用法代碼示例。如果您正苦於以下問題:Python hashlib.sha512方法的具體用法?Python hashlib.sha512怎麽用?Python hashlib.sha512使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類hashlib
的用法示例。
在下文中一共展示了hashlib.sha512方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_command_line
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def parse_command_line():
parser= argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required = True)
group.add_argument('--md5',help='specifies MD5 algorithm',action='store_true')
group.add_argument('--sha256', help='specifies SHA256 algorithm', action='store_true')
group.add_argument('--sha512', help='specifies SHA512 algorithm', action='store_true')
parser.add_argument('-d','--dirpath',type=ValidateDirectory,required=True,help="specify the root path for hashing")
parser.add_argument('-r','--reportpath',type=ValidateDirectoryWritable,required=True,help="specify the path for reports and logs will be written")
global gl_args
global gl_hashType
gl_args = parser.parse_args()
if gl_args.md5:
gl_hashType='MD5'
elif gl_args.sha256:
gl_hashType='SHA256'
elif gl_args.sha512:
gl_hashType='SHA512'
else:
gl_hashType='unknown'
示例2: check_auth
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def check_auth(username, password):
ADMIN_512 = 'bf33ea356054cbac9cc9b65c475b8b7ea0a1347d1f28b8f92cf065614cc7853b4f1d66e498111aed84f8741feeda553229c970fdaec5cf60b8c00250bbdcb6cf'
ATTACKER_512 = '56aff393533461d974487c1222171a5a6a0a6fe883c7658070ee3c38022c52a3de0d74a634a909b2eb78bd109bc830d81939033a11e7fc77b5458848264f57f3'
if username == 'admin':
admin_512 = sha512(password.strip()).hexdigest()
return admin_512 == ADMIN_512
elif username == 'attacker':
attacker_512 = sha512(password.strip()).hexdigest()
return attacker_512 == ATTACKER_512
else:
return False
示例3: is_valid_transaction
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def is_valid_transaction(txn):
# validate transactions signature
header = TransactionHeader()
header.ParseFromString(txn.header)
context = create_context('secp256k1')
public_key = Secp256k1PublicKey.from_hex(header.signer_public_key)
if not context.verify(txn.header_signature,
txn.header,
public_key):
LOGGER.debug("transaction signature invalid for txn: %s",
txn.header_signature)
return False
# verify the payload field matches the header
txn_payload_sha512 = hashlib.sha512(txn.payload).hexdigest()
if txn_payload_sha512 != header.payload_sha512:
LOGGER.debug("payload doesn't match payload_sha512 of the header"
"for txn: %s", txn.header_signature)
return False
return True
示例4: _wrap_consensus_message
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def _wrap_consensus_message(self, content, message_type, connection_id):
_, name, version, _ = self._consensus_registry.get_active_engine_info()
header = ConsensusPeerMessageHeader(
signer_id=self._public_key,
content_sha512=hashlib.sha512(content).digest(),
message_type=message_type,
name=name,
version=version,
).SerializeToString()
signature = bytes.fromhex(self._identity_signer.sign(header))
message = ConsensusPeerMessage(
header=header,
content=content,
header_signature=signature)
return message
示例5: generate_transaction
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def generate_transaction(self, payload='txn', deps=None):
payload_encoded = payload.encode('utf-8')
hasher = hashlib.sha512()
hasher.update(payload_encoded)
txn_header = TransactionHeader(
dependencies=([] if deps is None else deps),
batcher_public_key=self.signer.get_public_key().as_hex(),
family_name='test',
family_version='1',
nonce=_generate_id(16),
payload_sha512=hasher.hexdigest().encode(),
signer_public_key=self.signer.get_public_key().as_hex()
).SerializeToString()
txn = Transaction(
header=txn_header,
header_signature=self.signer.sign(txn_header),
payload=payload_encoded)
return txn
示例6: send
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def send(self):
name = uuid4().hex[:20]
txns = [
self._factory.create_transaction(
cbor.dumps({
'Name': name,
'Verb': 'set',
'Value': 1000
}),
inputs=[
self._namespace + self._factory.sha512(name.encode())[-64:]
],
outputs=[
self._namespace + self._factory.sha512(name.encode())[-64:]
],
deps=[])
]
self._rest.send_batches(self._factory.create_batch(txns))
示例7: _hash
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def _hash(data):
'''Compute the SHA-512 hash and return the result as hex characters.'''
return hashlib.sha512(data).hexdigest()
示例8: _hash
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def _hash(data):
return hashlib.sha512(data).hexdigest()
示例9: send_details
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def send_details(self):
rnd = struct.pack("<I", random.randint(0, 4294967295))
m = hashlib.sha512()
m.update(rnd)
m.update(self.key)
ciphertext = m.digest()
return rnd+ciphertext
示例10: check_details
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def check_details(self, msg):
rnd = msg[0:4]
ciphertext = msg[4:68]
m = hashlib.sha512()
m.update(rnd)
m.update(self.key)
if ciphertext == m.digest():
return True
return False
示例11: test_valid_hash_algorithm
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def test_valid_hash_algorithm():
expected = hashlib.sha512
actual = HashAlgorithms.get_algorithm(0x1)
assert actual == expected
示例12: get_algorithm
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def get_algorithm(hash):
return {
HashAlgorithms.SHA_512: hashlib.sha512
}[hash]
示例13: hmac_sha512
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def hmac_sha512(chain_code: bytes, data: bytes) -> bytes:
"""
As specified by RFC4231 - https://tools.ietf.org/html/rfc4231
"""
return hmac.new(chain_code, data, hashlib.sha512).digest()
示例14: pbkdf2_hmac_sha512
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def pbkdf2_hmac_sha512(passcode: str, salt: str) -> bytes:
return hashlib.pbkdf2_hmac(
"sha512",
passcode.encode("utf-8"),
salt.encode("utf-8"),
PBKDF2_ROUNDS,
)
示例15: __eddsa_hash
# 需要導入模塊: import hashlib [as 別名]
# 或者: from hashlib import sha512 [as 別名]
def __eddsa_hash(data):
return hashlib.sha512(data).digest()