-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcbkdf.py
34 lines (28 loc) · 811 Bytes
/
cbkdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import base64
import os
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.concatkdf import ConcatKDFHash
from cryptography.hazmat.backends import default_backend
# The sample code is extracted from the book Python Cryptography
# The book can be downloaded from https://leanpub.com/cryptop
# Online Crypto Playgroud https://8gwifi.org
# Author Anish Nath
backend = default_backend()
otherinfo = b"concatkdf-example"
ckdf = ConcatKDFHash(
algorithm=hashes.SHA256(),
length=32,
otherinfo=otherinfo,
backend=backend
)
# CKDF Derive key
key = ckdf.derive(b"input key")
base64.b64encode(key)
# CKDF Verify Key
ckdf = ConcatKDFHash(
algorithm=hashes.SHA256(),
length=32,
otherinfo=otherinfo,
backend=backend
)
ckdf.verify(b"input key", key)