blob: 6aa7ed25d0c5289a9f3f15164b574e8abcf60a81 [file] [log] [blame]
Alex Gaynorf6c47e92013-08-08 07:16:01 -07001Symmetric Encryption
2====================
3
4Symmetric encryption is a way to encrypt (hide the plaintext value) material
5where the encrypter and decrypter both use the same key.
6
7Block ciphers
8-------------
9
10Block ciphers work by encrypting content in chunks, often 64- or 128-bits. They
11combine an underlying algorithm (such as AES), with a mode (such as CBC, CTR,
12or GCM). A simple example of encrypting content with AES is:
13
14.. code-block:: pycon
15
16 >>> from cryptography.primitives import BlockCipher, CBC
17 >>> from cryptography.primitives.aes import AES
18 >>> cipher = BlockCipher(AES(key), CBC(iv))
19 >>> cipher.encrypt("my secret message") + cipher.finalize()
20 # The ciphertext
21 [...]
22
Alex Gaynor0ca7fdb2013-08-08 07:35:26 -070023Here ``key`` is the encryption key (which must be kept secret), and ``iv`` is
24the initialization vector (which should be random). Exactly what form these
25values should take is described for each of the ciphers and modes.
26
27``encrypt()`` should be called repeatedly with additional plaintext, and it
28will return the encrypted bytes, if there isn't enough data, it will buffer it
29internally. ``finalize()`` should be called at the end, and will return
30whatever data is left.
Alex Gaynord96d1002013-08-08 07:37:26 -070031
32Ciphers
33~~~~~~~
34
35AES
36+++
37
38Modes
39~~~~~
40
41CBC
42+++