From 0f986114004a04cab8fea477e0eace29adab9531 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Tue, 30 Dec 2014 09:43:24 -0800 Subject: Make the symmetric-enc example an example Making some minor tweaks to the doc example for symmetric encryption so it is an actual, runable example. --- docs/hazmat/primitives/symmetric-encryption.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/hazmat/primitives/symmetric-encryption.rst') diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index 8d3769f5..83230287 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -35,10 +35,12 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. .. doctest:: + >>> import os >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes >>> from cryptography.hazmat.backends import default_backend >>> backend = default_backend() - >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend) + >>> key = os.urandom(24) + >>> cipher = Cipher(algorithms.AES(key), modes.CBC(os.urandom(16)), backend=backend) >>> encryptor = cipher.encryptor() >>> ct = encryptor.update(b"a secret message") + encryptor.finalize() >>> decryptor = cipher.decryptor() -- cgit v1.2.3 From e261d94c914b02ba132b13ff6c0613d026c630bc Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Sat, 3 Jan 2015 09:17:41 -0800 Subject: Assign iv to var and remove testsetup block --- docs/hazmat/primitives/symmetric-encryption.rst | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'docs/hazmat/primitives/symmetric-encryption.rst') diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index 83230287..d532ad1b 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -6,12 +6,6 @@ Symmetric encryption .. currentmodule:: cryptography.hazmat.primitives.ciphers -.. testsetup:: - - import binascii - key = binascii.unhexlify(b"0" * 32) - iv = binascii.unhexlify(b"0" * 32) - Symmetric encryption is a way to `encrypt`_ or hide the contents of material where the sender and receiver both use the same secret key. Note that symmetric @@ -39,8 +33,9 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. >>> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes >>> from cryptography.hazmat.backends import default_backend >>> backend = default_backend() - >>> key = os.urandom(24) - >>> cipher = Cipher(algorithms.AES(key), modes.CBC(os.urandom(16)), backend=backend) + >>> key = os.urandom(32) + >>> iv = os.urandom(16) + >>> 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() -- cgit v1.2.3 From 7e28fbb6ce3c193c9a0dc99504629cabc98d5fe6 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Sat, 3 Jan 2015 09:19:05 -0800 Subject: iv should be 32 bytes --- docs/hazmat/primitives/symmetric-encryption.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/hazmat/primitives/symmetric-encryption.rst') diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index d532ad1b..24854b1c 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -34,7 +34,7 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. >>> from cryptography.hazmat.backends import default_backend >>> backend = default_backend() >>> key = os.urandom(32) - >>> iv = os.urandom(16) + >>> iv = os.urandom(32) >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend) >>> encryptor = cipher.encryptor() >>> ct = encryptor.update(b"a secret message") + encryptor.finalize() -- cgit v1.2.3 From e5917781674c3678589571621c9b18153d2140b5 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Sat, 3 Jan 2015 21:58:25 -0800 Subject: IV should be 16 bytes --- docs/hazmat/primitives/symmetric-encryption.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/hazmat/primitives/symmetric-encryption.rst') diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index 24854b1c..d532ad1b 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -34,7 +34,7 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. >>> from cryptography.hazmat.backends import default_backend >>> backend = default_backend() >>> key = os.urandom(32) - >>> iv = os.urandom(32) + >>> iv = os.urandom(16) >>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend) >>> encryptor = cipher.encryptor() >>> ct = encryptor.update(b"a secret message") + encryptor.finalize() -- cgit v1.2.3