| 1 |
:mod:`Crypto.PublicKey` package |
| 2 |
=============================== |
| 3 |
|
| 4 |
In a public key cryptography system, senders and receivers do not use the same key. |
| 5 |
Instead, the system defines a *key pair*, with one of the keys being |
| 6 |
confidential (*private*) and the other not (*public*). |
| 7 |
|
| 8 |
.. csv-table:: |
| 9 |
:header: Algorithm, "Sender uses..", "Receiver uses..." |
| 10 |
|
| 11 |
Encryption, "Public key", "Private key" |
| 12 |
Signature, "Private key", "Public key" |
| 13 |
|
| 14 |
Unlike keys meant for symmetric cipher algorithms (typically just |
| 15 |
random bit strings), keys for public key algorithms have very specific |
| 16 |
properties. This module collects all methods to generate, validate, |
| 17 |
store and retrieve public keys. |
| 18 |
|
| 19 |
API principles |
| 20 |
-------------- |
| 21 |
|
| 22 |
Asymmetric keys are represented by Python objects. Each object can be either |
| 23 |
a *private* key or a *public* key (the method :meth:`has_private` can be used |
| 24 |
to distinguish them). |
| 25 |
|
| 26 |
A key object can be created in four ways: |
| 27 |
|
| 28 |
1. :func:`generate` at the module level (e.g. :func:`Crypto.PublicKey.RSA.generate`). |
| 29 |
The key is randomly created each time. |
| 30 |
2. :func:`import_key` at the module level (e.g. :func:`Crypto.PublicKey.RSA.import_key`). |
| 31 |
The key is loaded from memory. |
| 32 |
3. :func:`construct` at the module level (e.g. :func:`Crypto.PublicKey.RSA.construct`). |
| 33 |
The key will be built from a set of sub-components. |
| 34 |
4. :meth:`publickey` at the object level (e.g. :meth:`Crypto.PublicKey.RSA.RsaKey.publickey`). |
| 35 |
The key will be the public key matching the given object. |
| 36 |
|
| 37 |
A key object can be serialized via its :meth:`export_key` method. |
| 38 |
|
| 39 |
Keys objects can be compared via the usual operators ``==`` and ``!=`` (note that the two halves of the same key, |
| 40 |
*private* and *public*, are considered as two different keys). |
| 41 |
|
| 42 |
Available key types |
| 43 |
------------------- |
| 44 |
|
| 45 |
.. toctree:: |
| 46 |
:hidden: |
| 47 |
|
| 48 |
rsa |
| 49 |
ecc |
| 50 |
dsa |
| 51 |
|
| 52 |
* :doc:`RSA keys <rsa>` |
| 53 |
* :doc:`Elliptic Curve keys <ecc>` |
| 54 |
* :doc:`DSA keys (obsolete) <dsa>` |
| 55 |
|
| 56 |
Obsolete key type |
| 57 |
----------------- |
| 58 |
|
| 59 |
.. toctree:: |
| 60 |
:hidden: |
| 61 |
|
| 62 |
elgamal |
| 63 |
|
| 64 |
* :doc:`ElGamal keys <elgamal>` |
| 65 |
|