本文整理汇总了Python中pyblake2.blake2s方法的典型用法代码示例。如果您正苦于以下问题:Python pyblake2.blake2s方法的具体用法?Python pyblake2.blake2s怎么用?Python pyblake2.blake2s使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyblake2
的用法示例。
在下文中一共展示了pyblake2.blake2s方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_passphrase
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def from_passphrase(cls, email, passphrase):
"""
This performs key derivation from an email address and passphrase according
to the miniLock specification.
Specifically, the passphrase is digested with a standard blake2s 32-bit digest,
then it is passed through scrypt with the email address as salt value using
N = 217, r = 8, p = 1, L = 32.
The 32-byte digest from scrypt is then used as the Private Key from which
the public key is derived.
"""
pp_blake = pyblake2.blake2s(cls.ensure_bytes(passphrase)).digest()
#pp_scrypt = scrypt.hash(pp_blake, cls.ensure_bytes(email), 2**17, 8, 1, 32)
pp_scrypt = pylibscrypt.scrypt(pp_blake, cls.ensure_bytes(email), 2**17, 8, 1, 32)
key = nacl.public.PrivateKey(pp_scrypt)
return cls(key.public_key, key)
示例2: new
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def new(cls, file_name, file_or_contents, sender, recipients):
"""
Constructs (that is, encrypts) a new miniLock file from sender to recipients.
"""
assert_type_and_length('recipients', recipients, list, minL=1)
assert_type_and_length('sender', sender, UserLock)
for R in recipients:
assert_type_and_length('recipient', R, (str, UserLock))
recipients = list(set(recipients))
# Encrypt file with secret key using file_contents and file_name
file_key = os.urandom(32)
file_nonce = os.urandom(16)
file_cipher = SymmetricMiniLock.from_key(file_key)
ciphertext = b''.join(file_cipher.encrypt(file_or_contents, file_name, file_nonce))
file_info = {
'fileKey' : b64encode(file_key),
'fileNonce' : b64encode(file_nonce),
'fileHash' : b64encode(pyblake2.blake2s(ciphertext).digest())
}
header = MiniLockHeader.new(file_info, sender, recipients)
b_header = header.to_bytes()
encrypted_file = b'miniLock' + len(b_header).to_bytes(4, 'little') + b_header + ciphertext
return cls(encrypted_file)
示例3: decrypt
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def decrypt(self, recipient_key):
"""
recipient_key: UserLock with a private key part.
returns: filename, decrypted file contents
"""
if recipient_key.private_key is None:
raise ValueError("Cannot decrypt with this key; no private key part found.")
header = MiniLockHeader(self.header)
# Create ephemeral public key for authenticated decryption of metadata.
# TODO: Future-proof this by making it try to decrypt a b58 ephem ID if available?
decryptInfo = header.decrypt(recipient_key)
file_info = decryptInfo['fileInfo']
file_hash = file_info['fileHash']
if not b64decode(file_hash) == pyblake2.blake2s(self.chunks_block).digest():
raise ValueError("ciphertext does not match given hash!")
symbox = SymmetricMiniLock.from_key(b64decode(file_info['fileKey']))
filename, *filechunks = symbox.decrypt(self.chunks_block, b64decode(file_info['fileNonce']))
try:
filename = filename.decode('utf8')
except Exception as E:
raise ValueError("Cannot decode filename to UTF8 string: '{}'".format(filename))
sender = decryptInfo['senderID']
return filename, sender, b''.join(filechunks)
示例4: bf
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def bf(h, dictionary):
f = open(dictionary, 'r')
lines = f.readlines()
lines = lines.replace('\n', '')
print('\033[1;34m[*]\033[0m Starting Brute Force - hash = ' + h)
for i in lines:
m = pyblake2.blake2s()
m.update(i)
h2 = m.hexdigest()
if h == h2:
print('\033[1;32m[+]\033[0m Hash Cracked! - Password = ' + i)
exit()
print('\033[1;31m[-]\033[0m Hash could not be cracked!')
示例5: update
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def update(client, data):
if client.features.bootloader_mode is False:
raise RuntimeError("Device must be in bootloader mode")
resp = client.call(messages.FirmwareErase(length=len(data)))
# TREZORv1 method
if isinstance(resp, messages.Success):
resp = client.call(messages.FirmwareUpload(payload=data))
if isinstance(resp, messages.Success):
return
else:
raise RuntimeError("Unexpected result %s" % resp)
# TREZORv2 method
while isinstance(resp, messages.FirmwareRequest):
payload = data[resp.offset : resp.offset + resp.length]
digest = pyblake2.blake2s(payload).digest()
resp = client.call(messages.FirmwareUpload(payload=payload, hash=digest))
if isinstance(resp, messages.Success):
return
else:
raise RuntimeError("Unexpected message %s" % resp)
示例6: _blake2s
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def _blake2s(self, ofs, depth, is_last):
return blake2s(node_offset=ofs, node_depth=depth, last_node=is_last,
depth=2, inner_size=32, fanout=self.parallelism)
示例7: from_id
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def from_id(cls, id):
"""
This decodes an ID to a public key and verifies the checksum byte. ID
structure in miniLock is the base58 encoded form of the public key
appended with a single-byte digest from blake2s of the public key, as a
simple check-sum.
"""
decoded = cls.ensure_bytes(base58.b58decode(id))
assert_type_and_length('id', decoded, bytes, L=33)
pk = nacl.public.PublicKey(decoded[:-1])
cs = decoded[-1:]
if cs != pyblake2.blake2s(pk.encode(), 1).digest():
raise ValueError("Public Key does not match its attached checksum byte: id='{}', decoded='{}', given checksum='{}', calculated checksum={}".format(id, decoded, cs, pyblake2.blake2s(pk.encode(), 1).digest()))
return cls(pk)
示例8: userID
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def userID(self):
return base58.b58encode( self.public_key.encode() +
pyblake2.blake2s(self.public_key.encode(), 1).digest() )
示例9: _header_digest
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def _header_digest(header: c.Container, header_type: c.Construct) -> bytes:
stripped_header = header.copy()
stripped_header.sigmask = 0
stripped_header.signature = b"\0" * 64
header_bytes = header_type.build(stripped_header)
return pyblake2.blake2s(header_bytes).digest()
示例10: build_pszTimestamp
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def build_pszTimestamp(coinname, timestamp):
# Build the timestamp. First, replace all {XYZ}
for coin in re.findall(r'\{[A-Z]{3}\}', timestamp):
timestamp = timestamp.replace(coin, get_latest_block_str(coin[1:4]))
verb("timestamp after substitution: " + timestamp)
return coinname + \
blake2s(timestamp.encode('UTF-8')).hexdigest()
示例11: validate
# 需要导入模块: import pyblake2 [as 别名]
# 或者: from pyblake2 import blake2s [as 别名]
def validate(fw: FirmwareType, skip_vendor_header=False) -> bool:
vendor_fingerprint = _header_digest(fw.vendor_header, VendorHeader)
fingerprint = digest(fw)
if not skip_vendor_header:
try:
# if you want to validate a custom vendor header, you can modify
# the global variables to match your keys and m-of-n scheme
cosi.verify_m_of_n(
fw.vendor_header.signature,
vendor_fingerprint,
V2_BOOTLOADER_M,
V2_BOOTLOADER_N,
fw.vendor_header.sigmask,
V2_BOOTLOADER_KEYS,
)
except Exception:
raise ValueError("Invalid vendor header signature.")
# XXX expiry is not used now
# now = time.gmtime()
# if time.gmtime(fw.vendor_header.expiry) < now:
# raise ValueError("Vendor header expired.")
try:
cosi.verify_m_of_n(
fw.firmware_header.signature,
fingerprint,
fw.vendor_header.vendor_sigs_required,
fw.vendor_header.vendor_sigs_n,
fw.firmware_header.sigmask,
fw.vendor_header.pubkeys,
)
except Exception:
raise ValueError("Invalid firmware signature.")
# XXX expiry is not used now
# if time.gmtime(fw.firmware_header.expiry) < now:
# raise ValueError("Firmware header expired.")
for i, expected_hash in enumerate(fw.firmware_header.hashes):
if i == 0:
# Because first chunk is sent along with headers, there is less code in it.
chunk = fw.code[: V2_CHUNK_SIZE - fw._code_offset]
else:
# Subsequent chunks are shifted by the "missing header" size.
ptr = i * V2_CHUNK_SIZE - fw._code_offset
chunk = fw.code[ptr : ptr + V2_CHUNK_SIZE]
if not chunk and expected_hash == b"\0" * 32:
continue
chunk_hash = pyblake2.blake2s(chunk).digest()
if chunk_hash != expected_hash:
raise ValueError("Invalid firmware data.")
return True
# ====== Client functions ====== #