-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscrypt.py
More file actions
39 lines (31 loc) · 777 Bytes
/
scrypt.py
File metadata and controls
39 lines (31 loc) · 777 Bytes
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
38
39
# 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.scrypt import Scrypt
from cryptography.hazmat.backends import default_backend
salt = os.urandom(16)
kdf = Scrypt(
salt=salt,
length = 32,
n = 2**14,
r=8,
p=1,
backend=default_backend()
)
#scrytp Derive key
key = kdf.derive(b"my password")
print base64.b64encode(key)
# ANSI X9.63 verify Function
kdf = Scrypt(
salt=salt,
length = 32,
n = 2**14,
r=8,
p=1,
backend=default_backend()
)
kdf.verify(b"my password", key)