Posts

Showing posts with the label Cryptography

Basics Of Python Encryption W/ Hashlib Sha1

Answer : The hashlib module provides hashing functions. While there is some relation to encryption, once you hash some data you can not go back to get the original data from the hash result. Instead of encripting the data you can take a different approach: creating a unique signature using a hash of the data and some secret. shared_private_key = "ABCDEF" def create_signature(data): return hashlib.sha1(repr(data) + "," + shared_private_key).hexdigest() def verify_signature(data, signature): return signature == create_signature(data) Finally, you send to the Website 2 the data plus the signature. That way you can be (mostly) sure that no unauthorized person tampered the data. What you want is an encryption library not one that just provides hash algorithms. With python's hashlib library: import hashlib m = hashlib.sha1() m.update("The quick brown fox jumps over the lazy dog") print(m.hexdigest()) Returns: 2fd4e1c67a2d28fced849ee...