Debian Codegraph @

Doc/src/cipher/aes.rst

raw
1 AES
2 ===
3
4 AES `(Advanced Encryption Standard)`__ is a symmetric block cipher standardized
5 by NIST_ . It has a fixed data block size of 16 bytes.
6 Its keys can be 128, 192, or 256 bits long.
7
8 AES is very fast and secure, and it is the de facto standard for symmetric
9 encryption.
10
11 As an example, encryption can be done as follows::
12
13 >>> from Crypto.Cipher import AES
14 >>>
15 >>> key = b'Sixteen byte key'
16 >>> cipher = AES.new(key, AES.MODE_EAX)
17 >>>
18 >>> nonce = cipher.nonce
19 >>> ciphertext, tag = cipher.encrypt_and_digest(data)
20
21 The recipient can obtain the original message using the same key
22 and the incoming triple ``(nonce, ciphertext, tag)``::
23
24 >>> from Crypto.Cipher import AES
25 >>>
26 >>> key = b'Sixteen byte key'
27 >>> cipher = AES.new(key, AES.MODE_EAX, nonce=nonce)
28 >>> plaintext = cipher.decrypt(ciphertext)
29 >>> try:
30 >>> cipher.verify(tag)
31 >>> print("The message is authentic:", plaintext)
32 >>> except ValueError:
33 >>> print("Key incorrect or message corrupted")
34
35 Constants for the modes of operation supported with AES (``mode`` parameter):
36
37 .. __: http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
38 .. _NIST: http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
39
40 .. automodule:: Crypto.Cipher.AES
41 :members:
42 :member-order: bysource