Encrypt & Decrypt using PyCrypto AES 256

后端 未结 12 1063
夕颜
夕颜 2020-11-22 13:07

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

12条回答
  •  野性不改
    2020-11-22 13:28

    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.

提交回复
热议问题