From 19fd5102cba1e581d6bfab78c5a26ef5819b36af Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Wed, 13 Mar 2019 00:39:49 +0000 Subject: [PATCH] Remove unnecessary dependency on pyca MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python’s built-in hashlib is capable of calculating SHA1. There’s no need to depend on a third party library which may or may not be available. --- pwned.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/pwned.py b/pwned.py index ecc8359..b2e1f0b 100644 --- a/pwned.py +++ b/pwned.py @@ -1,18 +1,10 @@ +import hashlib import requests -import cryptography -from base64 import b16encode import sys -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import hashes -def hash_password_sha1_hex(pwd): - digest = hashes.Hash(hashes.SHA1(), backend=default_backend()) - digest.update(pwd.encode('ASCII')) - sha1 = b16encode(digest.finalize()).decode('ASCII') - return sha1 def lookup_pwned_api(pwd): - sha1pwd = hash_password_sha1_hex(pwd) + sha1pwd = hashlib.sha1(pwd.encode('ascii')).hexdigest().upper() head = sha1pwd[:5] tail = sha1pwd[5:] @@ -32,4 +24,4 @@ if (api_return): else: print (sys.argv[1], "was not found") -exit() \ No newline at end of file +exit()