Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def decrypt_with_user_pw(self, filename, pw_for):
with file(filename) as fd:
nonce = fd.read(nacl.crypto_secretbox_NONCEBYTES)
prompt = 'Passphrase for decrypting {0} for {1}: '.format(pw_for, self.name)
k = scrypt.hash(getpass.getpass(prompt), pbp.scrypt_salt)[:nacl.crypto_secretbox_KEYBYTES]
return nacl.crypto_secretbox_open(fd.read(), nonce, k)
def decrypt_with_user_pw(self, filename, pw_for):
with file(filename) as fd:
nonce = fd.read(nacl.crypto_secretbox_NONCEBYTES)
prompt = 'Passphrase for decrypting {0} for {1}: '.format(pw_for, self.name)
k = scrypt.hash(getpass.getpass(prompt), pbp.scrypt_salt)[:nacl.crypto_secretbox_KEYBYTES]
return nacl.crypto_secretbox_open(fd.read(), nonce, k)
def decrypt(self, pkt):
peer, key = self.keydecrypt(pkt[1])
if key:
return peer, nacl.crypto_secretbox_open(pkt[2], pkt[0], key)
def decrypt(self, cipher, nonce):
if self.in_k == ('\0' * nacl.crypto_scalarmult_curve25519_BYTES):
# use pk crypto to decrypt the packet
return nacl.crypto_box_open(cipher, nonce, self.peer_id.cp, self.me_id.cs)
else:
# decrypt using chained keys
try:
return nacl.crypto_secretbox_open(cipher, nonce, self.in_k)
except ValueError:
# with previous key in case a prev send failed to be delivered
return nacl.crypto_secretbox_open(cipher, nonce, self.in_prev)
# k specifies an encryption key, which if not supplied, is derived from
# pwd which is queried from the user, if also not specified.
clearpwd = (pwd is None)
cleark = (k is None)
cnt=0
res = None
while cnt