From ad7d0841c22ef6c3fbfb2be34bd8f6aec526f247 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 7 Jul 2015 15:57:29 -0400 Subject: [PATCH] saltpass.py: Implement simple salted hash script --- .gitignore | 3 +++ programs/witness_node/saltpass.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 programs/witness_node/saltpass.py diff --git a/.gitignore b/.gitignore index 5cdb0935..c4d159d2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ witness_node_data_dir programs/witness_node/object_database/* object_database/* + +*.pyc +*.pyo diff --git a/programs/witness_node/saltpass.py b/programs/witness_node/saltpass.py new file mode 100755 index 00000000..6562fc23 --- /dev/null +++ b/programs/witness_node/saltpass.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import base64 +import getpass +import hashlib +import json +import os + +pw = getpass.getpass("enter your password: ") +pw_bytes = pw.encode("utf-8") +salt_bytes = os.urandom(8) +salt_b64 = base64.b64encode( salt_bytes ) +pw_hash = hashlib.sha256( pw_bytes + salt_bytes ).digest() +pw_hash_b64 = base64.b64encode( pw_hash ) + +print(json.dumps( +{ + "password_hash_b64" : pw_hash_b64.decode("ascii"), + "password_salt_b64" : salt_b64.decode("ascii"), +}, +sort_keys=True, +indent=3, separators=(',', ' : ') +))