I\'m trying to build two functions using PyCrypto that accept two parameters: the message and the key, and then encrypt/decrypt the message.
I found several links on
You can get a passphrase out of an arbitrary password by using a cryptographic hash function (NOT Python's builtin hash
) like SHA-1 or SHA-256. Python includes support for both in its standard library:
import hashlib
hashlib.sha1("this is my awesome password").digest() # => a 20 byte string
hashlib.sha256("another awesome password").digest() # => a 32 byte string
You can truncate a cryptographic hash value just by using [:16]
or [:24]
and it will retain its security up to the length you specify.