File: raw_sealed.rst

package info (click to toggle)
python-libnacl 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: python: 2,634; makefile: 149; sh: 3
file content (41 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
=========================
Raw Sealed Box Encryption
=========================

Sealed box is a variant of :doc:`public key encryption scheme </topics/raw_public>`
where the sender is not authenticated. This is done by generating an
ephemeral key pair, which the public key is prefixed to the cipher text.

First, generate a keypair for the receiver. The sender doesn't need a keypair.

.. code-block:: python

    import libnacl

    pk, sk = libnacl.crypto_box_keypair()

Then a sealed box is created by the sender, using the receiver's public key

.. code-block:: python

    msg = 'Quiet, quiet.  Quiet!  There are ways of telling whether she is a witch.'
    box = libnacl.crypto_box_seal(msg, pk)

The receiver then can decrypt the box using their keypair.

.. code-block:: python

    clear_msg = libnacl.crypto_box_seal_open(box, pk, sk)

To bring it all together:

.. code-block:: python

    import libnacl

    pk, sk = libnacl.crypto_box_keypair()

    msg = 'Quiet, quiet.  Quiet!  There are ways of telling whether she is a witch.'
    box = libnacl.crypto_box_seal(msg, pk)

    clear_msg = libnacl.crypto_box_seal_open(box, pk, sk)