writing a variable to a text file and encrypting it?

13,196

There are some Python packages worth checking out that deal with cryptography.

Cryptography

PyCrypto

A simple example from cryptography would be the following:

from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher_suite = Fernet(key)
cipher_text = cipher_suite.encrypt(b"A really secret message. Not for prying eyes.")
plain_text = cipher_suite.decrypt(cipher_text)
Share:
13,196
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    i know how to save a users input to a text file but how do i encrypt it? here is what i have for saving a users input to text file. i tried f.encrypt("Passwords_log.txt" but had no results

    import time
    password1 = input("Please type a password: ")
    print("Your password has passed the verification!")
    time.sleep(1)
    print("Saving and encrypting password...")
    time.sleep(2)
    f=open("Passwords_log.txt",'a')
    f.write(password)
    f.write('\n')
    f.close()
    print("Done!")