How to use the pysodium.crypto_secretbox_open function in pysodium

To help you get started, we’ve selected a few pysodium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stef / pbp / pbp / publickey.py View on Github external
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)
github stef / pbp / publickey.py View on Github external
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)
github stef / pbp / pbp / publickey.py View on Github external
def decrypt(self, pkt):
        peer, key = self.keydecrypt(pkt[1])
        if key:
            return peer, nacl.crypto_secretbox_open(pkt[2], pkt[0], key)
github stef / pbp / pbp / chaining.py View on Github external
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)
github stef / pbp / pbp / pbp.py View on Github external
# 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