aboutsummaryrefslogtreecommitdiffstats
path: root/docs/hazmat/primitives/symmetric-encryption.rst
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-26 09:31:06 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-26 09:31:06 -0800
commite60e1d782cb7c1abe68811092f7db342ed14b81f (patch)
tree555ed6a8cecd2759fd22dfbb41f6d61fd46b7788 /docs/hazmat/primitives/symmetric-encryption.rst
parent90501724c5b3d73fea5a4242fa09c32277c6c210 (diff)
parent6dc73a9bd475dfb7a3c18c65afaeb644cce3749f (diff)
downloadcryptography-e60e1d782cb7c1abe68811092f7db342ed14b81f.tar.gz
cryptography-e60e1d782cb7c1abe68811092f7db342ed14b81f.tar.bz2
cryptography-e60e1d782cb7c1abe68811092f7db342ed14b81f.zip
Merge pull request #227 from dreid/explicit-backend-in-hazmat
Explicit backend
Diffstat (limited to 'docs/hazmat/primitives/symmetric-encryption.rst')
-rw-r--r--docs/hazmat/primitives/symmetric-encryption.rst23
1 files changed, 18 insertions, 5 deletions
diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst
index 732af33c..4ab91408 100644
--- a/docs/hazmat/primitives/symmetric-encryption.rst
+++ b/docs/hazmat/primitives/symmetric-encryption.rst
@@ -12,6 +12,9 @@ Symmetric Encryption
key = binascii.unhexlify(b"0" * 32)
iv = binascii.unhexlify(b"0" * 32)
+ from cryptography.hazmat.bindings import default_backend
+ backend = default_backend()
+
Symmetric encryption is a way to encrypt (hide the plaintext value) material
where the sender and receiver both use the same key. Note that symmetric
@@ -22,7 +25,7 @@ For this reason it is *strongly* recommended to combine encryption with a
message authentication code, such as :doc:`HMAC </hazmat/primitives/hmac>`, in
an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
-.. class:: Cipher(algorithm, mode)
+.. class:: Cipher(algorithm, mode, backend)
Cipher objects combine an algorithm (such as
:class:`~cryptography.hazmat.primitives.ciphers.algorithms.AES`) with a
@@ -34,15 +37,23 @@ an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
.. doctest::
>>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
- >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
+ >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
>>> encryptor = cipher.encryptor()
>>> ct = encryptor.update(b"a secret message") + encryptor.finalize()
>>> decryptor = cipher.decryptor()
>>> decryptor.update(ct) + decryptor.finalize()
'a secret message'
- :param algorithms: One of the algorithms described below.
- :param mode: One of the modes described below.
+ :param algorithms: A
+ :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm`
+ provider such as those described
+ :ref:`below <symmetric-encryption-algorithms>`.
+ :param mode: A :class:`~cryptography.hazmat.primitives.interfaces.Mode`
+ provider such as those described
+ :ref:`below <symmetric-encryption-modes>`.
+ :param backend: A
+ :class:`~cryptography.hazmat.bindings.interfaces.CipherBackend`
+ provider.
.. method:: encryptor()
@@ -107,6 +118,8 @@ an "encrypt-then-MAC" formulation as `described by Colin Percival`_.
:meth:`update` and :meth:`finalize` will raise
:class:`~cryptography.exceptions.AlreadyFinalized`.
+.. _symmetric-encryption-algorithms:
+
Algorithms
~~~~~~~~~~
@@ -188,7 +201,7 @@ Weak Ciphers
>>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
>>> algorithm = algorithms.ARC4(key)
- >>> cipher = Cipher(algorithm, mode=None)
+ >>> cipher = Cipher(algorithm, mode=None, backend=backend)
>>> encryptor = cipher.encryptor()
>>> ct = encryptor.update(b"a secret message")
>>> decryptor = cipher.decryptor()