aboutsummaryrefslogtreecommitdiffstats
path: root/docs/hazmat/primitives
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2014-02-03 13:26:15 -0800
committerDavid Reid <dreid@dreid.org>2014-02-03 13:26:15 -0800
commit5df929ce2dea053626af4f8b3c3b98b81b359bda (patch)
tree35c08ab59f658a93c644efe99b65a75a902a052e /docs/hazmat/primitives
parent15ac790cfee3bf317f4d7a8c831daa7a694e6d7a (diff)
downloadcryptography-5df929ce2dea053626af4f8b3c3b98b81b359bda.tar.gz
cryptography-5df929ce2dea053626af4f8b3c3b98b81b359bda.tar.bz2
cryptography-5df929ce2dea053626af4f8b3c3b98b81b359bda.zip
HKDF example.
Diffstat (limited to 'docs/hazmat/primitives')
-rw-r--r--docs/hazmat/primitives/key-derivation-functions.rst26
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/hazmat/primitives/key-derivation-functions.rst b/docs/hazmat/primitives/key-derivation-functions.rst
index 48a066c9..a91d8ca9 100644
--- a/docs/hazmat/primitives/key-derivation-functions.rst
+++ b/docs/hazmat/primitives/key-derivation-functions.rst
@@ -129,6 +129,32 @@ Different KDFs are suitable for different tasks such as:
`HKDF`_ (HMAC-based Extract-and-Expand Key Derivation Function) is suitable
for deriving keys of a fixed size used for other cryptographic operations.
+ .. doctest::
+
+ >>> import os
+ >>> from cryptography.hazmat.primitives import hashes
+ >>> from cryptography.hazmat.primitives.kdf.hkdf import HKDF
+ >>> from cryptography.hazmat.backends import default_backend
+ >>> backend = default_backend()
+ >>> salt = os.urandom(16)
+ >>> info = b"hkdf-example"
+ >>> hkdf = HKDF(
+ ... algorithm=hashes.SHA256(),
+ ... length=32,
+ ... salt=salt,
+ ... info=info,
+ ... backend=backend
+ ... )
+ >>> key = hkdf.derive(b"input key)
+ >>> hkdf = HKDF(
+ ... algorithm=hashes.SHA256(),
+ ... length=32,
+ ... salt=salt,
+ ... info=info,
+ ... backend=backend
+ ... )
+ >>> hkdf.verify(b"input key", key)
+
:param algorithm: An instance of a
:class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm`
provider.