@nakov/

Argon2 in Python

Python

calculate derive key from a password using the Argon2 algorithm in Python

fork
loading
Files
  • main.py
  • requirements.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9845403743069858","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IGFyZ29uMiwgYmluYXNjaWkKCmhhc2ggPSBhcmdvbjIuaGFzaF9wYXNzd29yZF9yYXcoCiAgICB0aW1lX2Nvc3Q9MTYsIG1lbW9yeV9jb3N0PTIqKjE1LCBwYXJhbGxlbGlzbT0yLCBoYXNoX2xlbj0zMiwKICAgIHBhc3N3b3JkPWIncGFzc3dvcmQnLCBzYWx0PWInc29tZSBzYWx0JywgdHlwZT1hcmdvbjIubG93X2xldmVsLlR5cGUuSUQpCnByaW50KCJBcmdvbjIgcmF3IGhhc2g6IiwgYmluYXNjaWkuaGV4bGlmeShoYXNoKSkKCmFyZ29uMkhhc2hlciA9IGFyZ29uMi5QYXNzd29yZEhhc2hlcigKICAgIHRpbWVfY29zdD0xNiwgbWVtb3J5X2Nvc3Q9MioqMTUsIHBhcmFsbGVsaXNtPTIsIGhhc2hfbGVuPTMyLCBzYWx0X2xlbj0xNikKaGFzaCA9IGFyZ29uMkhhc2hlci5oYXNoKCJwYXNzd29yZCIpCnByaW50KCJBcmdvbjIgaGFzaCAocmFuZG9tIHNhbHQpOiIsIGhhc2gpCgp2ZXJpZnlWYWxpZCA9IGFyZ29uMkhhc2hlci52ZXJpZnkoaGFzaCwgInBhc3N3b3JkIikKcHJpbnQoIkFyZ29uMiB2ZXJpZnkgKGNvcnJlY3QgcGFzc3dvcmQpOiIsIHZlcmlmeVZhbGlkKQoKdHJ5OgogICAgYXJnb24ySGFzaGVyLnZlcmlmeShoYXNoLCAid3JvbmcxMjMiKQpleGNlcHQ6CiAgICBwcmludCgiQXJnb24yIHZlcmlmeSAoaW5jb3JyZWN0IHBhc3N3b3JkKToiLCBGYWxzZSkK"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import argon2, binascii

hash = argon2.hash_password_raw(
    time_cost=16, memory_cost=2**15, parallelism=2, hash_len=32,
    password=b'password', salt=b'some salt', type=argon2.low_level.Type.ID)
print("Argon2 raw hash:", binascii.hexlify(hash))

argon2Hasher = argon2.PasswordHasher(
    time_cost=16, memory_cost=2**15, parallelism=2, hash_len=32, salt_len=16)
hash = argon2Hasher.hash("password")
print("Argon2 hash (random salt):", hash)

verifyValid = argon2Hasher.verify(hash, "password")
print("Argon2 verify (correct password):", verifyValid)

try:
    argon2Hasher.verify(hash, "wrong123")
except:
    print("Argon2 verify (incorrect password):", False)