We will be using the 'cryptography' package to encrypt and decrypt our password file.
Cryptography gives us symmetric encoding method, with which we can encode and decode using a single key.
cryptography using pip or conda tool.
Then import it into your program using
After that get your data to be encrypted into the program
After that create a key and save it to a file to use at the time of decryption.
And create an object to encrypt the data.
Then use that object to encrypt the data, and save the data to a new file.
Now you would have a new file with the encrypted text.
If you are having a problem with reading or writing bytes to a file, use the decode function to convert bytes to string and encode to convert string to bytes.
See the code at Github