Derwynd's Weblog

Derwynd's Weblog

File Password Protection

A > How do I password protect / encrypt a file within Linux using OpenSSL ?

The file we will encrypt will be the file secretfile.txt.As you can see it is just a plain text file.

Encrypt File

Use the openssl comand to encrypt your file and then test the new file is fully encrypted.

$ openssl aes-256-cbc -salt -in secretfile.txt -out secretfile.txt.aes
enter aes-256-cbc encryption password:
Verifying – enter aes-256-cbc encryption password:

$ cat secretfile.txt.aes
binary data

Decrypt File

Decrypt the file and then confirm the decypted file is readable.

$ openssl aes-256-cbc -d -salt -in secretfile.txt.aes -out secretfile.txt
enter aes-256-cbc decryption password:

$ cat secretfile.txt
This is a secret file that we do not want anyone to read.

B > How do I password protect / encrypt a file within Linux using Mcrypt ?

Encrypt File

Use the mcrypt comand to encrypt your file and then test the new file is fully encrypted.

$ mcrypt secretfile.txt

Output:
Enter the passphrase (maximum of 512 characters)
Please use a combination of upper and lower case letters and numbers.
Enter passphrase:
Enter passphrase:

A new file is created with the extension .nc

$ ls secretfile.txt.nc

Decrypt File

Decrypt the file and then confirm the decypted file is readable.

$ mcrypt -d secretfile.txt.nc

Output:

Enter passphrase:
File secretfile.txt.nc was decrypted.

C > How do I password protect / encrypt a file within Linux using GPG ?

Encrypt File

Use the gpg comand to encrypt your file and then test the new file is fully encrypted.

$ gpg -c secretfile.txt

Output:
Enter passphrase:
Repeat passphrase:

This will create a secretfile.txt.gpg file.

Decrypt File

Decrypt the file and then confirm the decypted file is readable.

$ gpg secretfile.txt.gpg

Decrypt file and write output to file

$ gpg secretfile.txt.gpg -o somefile.txt


Easier method is to create a file using vim with the -x flag

vim -x

Advertisements

March 5, 2010 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: