How to use the pysodium.crypto_box 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 / pysodium / test / test_pysodium.py View on Github external
def test_crypto_box_open(self):
        m = b"howdy"
        pk, sk = pysodium.crypto_box_keypair()
        n = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
        c = pysodium.crypto_box(m, n, pk, sk)
        plaintext = pysodium.crypto_box_open(c, n, pk, sk)
        self.assertEqual(m, plaintext)
github stef / pbp / pbp / chaining.py View on Github external
keyfdir="%s/sk/.%s" % (self.basedir, self.me)
        if not os.path.exists(keyfdir):
            os.mkdir(keyfdir)
        fname='%s/%s' % (keyfdir, self.peer)
        nonce = nacl.randombytes(nacl.crypto_box_NONCEBYTES)
        ctx=''.join((self.e_in,
                     self.e_out,
                     self.peer_pub,
                     self.out_k,
                     self.in_k,
                     self.in_prev))
        if not self.me_id:
            self.me_id = publickey.Identity(self.me, basedir=self.basedir)
        with open(fname,'w') as fd:
            fd.write(nonce)
            fd.write(nacl.crypto_box(ctx, nonce, self.me_id.cp, self.me_id.cs))
github stef / pbp / pbp / publickey.py View on Github external
def keyencrypt(self, key, recipients=None):
        c=[]
        for r in recipients:
            nonce = nacl.randombytes(nacl.crypto_box_NONCEBYTES)
            c.append((nonce, nacl.crypto_box(key, nonce, r.cp, self.cs)))
        return c
github stef / pbp / pbp / chaining.py View on Github external
def encrypt(self,plain):
        if self.out_k == ('\0' * nacl.crypto_scalarmult_curve25519_BYTES):
            # encrypt using public key
            nonce = nacl.randombytes(nacl.crypto_box_NONCEBYTES)
            cipher= nacl.crypto_box(plain, nonce, self.peer_id.cp, self.me_id.cs)
        else:
            # encrypt using chaining mode
            nonce = nacl.randombytes(nacl.crypto_secretbox_NONCEBYTES)
            cipher = nacl.crypto_secretbox(plain, nonce, self.out_k)

        return cipher, nonce
github stef / pbp / publickey.py View on Github external
def keyencrypt(self, key, recipients=None):
        c=[]
        for r in recipients:
            nonce = nacl.randombytes(nacl.crypto_box_NONCEBYTES)
            c.append((nonce, nacl.crypto_box(key, nonce, r.cp, self.cs)))
        return c
github HUEBRTeam / PrimeServer / pyproto / prime.py View on Github external
def EncryptPacket(packet, pk, sk):
    nounce = LAST_NOUNCE
    data = pysodium.crypto_box(packet, nounce, pk, sk)
    return struct.pack("