Reputation: 2797
I need to encrypt a file, send it to another person, who then can only decrypt it using shell.
I usually encrypt the file with the openssl
command: openssl enc -aes-256-cbc -salt -in [filename] -out [file out name] -pass file:[direct path to key file]
, then send the file.
The other person then would decrypt the file again with the openssl
command: openssl enc -d -aes-256-cbc -in [encrypted file] -out [file out name] -pass file:[direct path to key file]
I would use os.system
to do this, but I feel like there has to be another way to encrypt the file with python which then could be decrypted on the shell side.
Upvotes: 1
Views: 2780
Reputation: 54302
Do you need to use openssl
?
I use command line GnuPG and there is very nice Python library: python-gnupg . It is a wrapper over command line gpg
so they work simply the same.
Instead of key file (I think it contains password) you can use asymmetric cryptography. Create private/public pairs of keys for each part and then encrypt message using recipient public key and sigg it using sender private key. Recipient will check signature of sender using sender public key and recipient will decrypt message using her private key. Private keys can be protected by password but if you are sure your environments are safe you can use empty passwords.
Upvotes: 2