Environment
Ubuntu 16.04 x64
OpenSSL 1.0.2g
Encrypt a file
First,Let’s see What cryptographic algorithms does OpensSL contain.1
$ openssl list-cipher-commands
Use the command above to see the password algorithm you can use.
Now,create a test file for experiment.
Here I choose aes-256-cbc to encrypt this file.1
$ openssl enc -aes-256-cbc -pass pass:test -p -in test.txt -out test.enc
enc
– using the enc operation of OpenSSL for encryption-aes-256-cbc
– the cipher used-pass pass:<password>
– point out the password used-e
– encrypt-p
– print out the salt,key and iv-in file
– specify the input file absolute path-out file
– specify the output file absolute path
Then,We usecat
to viewtest.enc
Decrypt a file
1
$ openssl enc -aes-256-cbc -pass pass:test -d -in test.enc -out decrypt_file.txt -p
enc
– using the enc operation of OpenSSL for encryption-aes-256-cbc
– the cipher used-pass pass:<password>
– point out the password used-d
– decrypt-p
– print out the salt,key and iv-in file
– specify the input file absolute path-out file
– specify the output file absolute path