DEV Community


Securing your passwords with python

prateekbud profile image Prateek budhiraja ・1 min read

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.
Let's start,


First, install 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.


Decrypting is fairly simple as well, we just need to import the key and the encrypted text into our program and just apply the decrypt function onto it.

See the code at Github

Discussion (0)

Editor guide