-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathx963kdf.py
37 lines (28 loc) · 817 Bytes
/
x963kdf.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
35
36
37
# 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
import base64
import os
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF
from cryptography.hazmat.backends import default_backend
sharedinfo = b"ANSI X9.63 Example"
backend = default_backend()
kdf = X963KDF(
algorithm=hashes.SHA256(),
length=32,
sharedinfo=sharedinfo,
backend=backend
)
# ANSI X9.63 Kdf Function
key = kdf.derive(b"input key")
base64.b64encode(key)
# ANSI X9.63 verify Function
kdf = X963KDF(
algorithm=hashes.SHA256(),
length=32,
sharedinfo=sharedinfo,
backend=backend
)
kdf.verify(b"input key", key)