Encrypt / decrypt data in python with salt

前端 未结 2 384
春和景丽
春和景丽 2021-01-30 11:34

I\'d like to know basically how can I encrypt data with a generated salt key and then decrypt it using python ?

i\'ve gone trough a lot of websites and modules, and they

2条回答
  •  生来不讨喜
    2021-01-30 12:33

    You don't need anything else than RNCryptor:

    import rncryptor
    
    data = '...'
    password = '...'
    
    # rncryptor.RNCryptor's methods
    cryptor = rncryptor.RNCryptor()
    encrypted_data = cryptor.encrypt(data, password)
    decrypted_data = cryptor.decrypt(encrypted_data, password)
    assert data == decrypted_data
    
    # rncryptor's functions
    encrypted_data = rncryptor.encrypt(data, password)
    decrypted_data = rncryptor.decrypt(encrypted_data, password)
    assert data == decrypted_data
    

    It provides semantically secure (random salt and IV for each encryption) encryption and includes secure integrity checking (ciphertext cannot be manipulated without noticing) through HMAC.

    RNCryptor also has a specific data format so you don't have to think about that and implementations in many languages.

提交回复
热议问题