I used to write an article about encrypting and decrypting using the python library, but I realized that in most cases it is enough to run openssl from a command without doing that. : sweat_smile:
Operation check environment arch linux openssl 1.1.1 python3.8.1
$ openssl enc -e -aes-256-cbc -k 'password' -in original_file -out encrypted_file
With openssl 1.1.1, you will get a warning "Using -iter or -pbkdf2 would be better.", But be aware that with this option you will not be able to decrypt with older versions.
decrypt.py
from subprocess import run, PIPE
password = 'password'
file_path = 'encrypted_file'
completed = run(args=[
'openssl', 'enc', '-d', '-aes-256-cbc',
'-k', password, '-in', file_path],
check=True, stdout=PIPE)
print(completed.stdout.decode())
Recommended Posts