How to encrypt a file with a password using OpenSSL


Reference of commands to encrypt a file with a password using OpenSSL.

Encryption

To encrypt a file:

1
openssl enc -aes256 -salt -in file.txt -out file.txt.enc

You will be prompted to enter an encryption password. If you want to specify the password in the command use the -pass parameter, for example to encrypt with the password myPassword run:

1
openssl enc -aes256 -salt -in file.txt -out file.txt.enc -pass pass:myPassword

To list the available encryption algorithms run:

1
openssl list-cipher-commands

Decryption

To decrypt a file:

1
openssl enc -aes256 -d -in file.txt.enc -out file.txt

You will be prompted to enter the decryption password.

To specify the password in the command use the -pass parameter. For example to decrypt using the password myPassword run:

1
openssl enc -aes256 -d -in file.txt.enc -out file.txt -pass pass:myPassword

References