Created
February 4, 2016 09:26
-
-
Save grokasm/3f4a8f886ee86f8e2e53 to your computer and use it in GitHub Desktop.
A simple command line program to calculate the SHA256 hash digest of a string input
This file contains 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
#!/usr/bin/env python | |
import argparse | |
import hashlib | |
import json | |
def sha256_hash(data): | |
data_sha256 = hashlib.sha256(json.dumps(data, sort_keys=True)).hexdigest() | |
return data_sha256 | |
def main(): | |
parser = argparse.ArgumentParser(description="Calculate a SHA 256 hash from an input phrase") | |
parser.add_argument('-i', '--input', type=str, required=True) | |
args = parser.parse_args() | |
print 'The input phrase is "%s"' % args.input | |
print 'The SHA256 hash of that phrase is: %s' % sha256_hash(args.input) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment