simple encrypt/decrypt lib in python with private key

前端 未结 5 858
[愿得一人]
[愿得一人] 2021-01-31 04:07

Is there a simple way to encrypt/decrypt a string with a key?

Something like:

key = \'1234\'
string =  \'hello world\'
encrypted_string = encrypt(key, st         


        
5条回答
  •  无人及你
    2021-01-31 04:40

    The simplest and fastest way to encrypt short text fragment with preshaired key is use one of cryptohash functions (md5, sha etc).

    i.e. calc md5 of your key, then xor your string fragment with this md5 hash. if you need to encode text fragmen longer than length of md5 - do md5(md5 hash) and encrypt next fragment.

    Security of this solution is worse than with 3-DES but enough in average case (i.e. to store not very secure password in config file) and it doesn't requre anything besides base python distro.

    If you need better security - look for one of AES, Blowfish etc implementation, but to really benefit AES you need to do some additional work to mix your data with random ones.

提交回复
热议问题