Created
July 11, 2017 20:56
-
-
Save bsiegfreid/2a028bc71bdf34bdcb904fe88264ea09 to your computer and use it in GitHub Desktop.
Example of hashing a password.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import binascii | |
import os | |
import sys | |
# salt should be generated once per user | |
# if python 3.6 use salt = secrets.token_bytes(8) | |
salt = os.urandom(8) | |
# convert user provided password to bytes | |
password = bytes(sys.argv[1], 'utf-8') | |
dk = hashlib.pbkdf2_hmac('sha512', # algorithm name | |
password, # must be binary | |
salt, # 64 bit salt | |
10000 # Minimum 10,000 iterations per NIST Aug 2016 | |
) | |
# convert to hexidecimal | |
hexed = binascii.hexlify(dk) | |
print(hexed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment