33

I need to be able to encrypt/decrypt a single text file stored on my external HD in 12.04 LTS, preferably a GUI application, if any, or the command line otherwise. Thank you.

41

A simple way to encrypt a single file is with openssl:

openssl des3 < youfile.txt > yourfile.txt.des3

This will prompt you for a passphrase, which you will need to enter later when decrypting the file.

openssl des3 -d < yourfile.txt.des3 > yourfile.txt.decrypted

To make this "graphical" you could put it in a Nautilus script and make it accessible from the context menu. (See the docs of Nautilus for that.)

UPDATE

des3 is just an example. Run openssl list-cipher-algorithms to see the full list of ciphers.

  • 9
    Why des3? You can do much better encryption faster with openssl aes-128-cbc – Brendan Long Jun 14 '13 at 19:46
  • @BrendanLong: I guess the reason is that aes-128-cbc in not mentioned in man openssl - I wonder why. It works, though. – Walter Tross Dec 21 '13 at 2:09
22

Lets assume that a person wants to encrypt a file called 'message.txt':

1. Encrypting a file using GPG, for personal use

I. Using a passphrase to encrypt the file (and not the private key)

I.i. The command: gpg -c message.txt does it; it asks for a password (and a password confirmation) and generates an encrypted 'message.txt.gpg', which is binary.

I.ii. If you want to generate an ASCII encrypted file, which is base64(i think) of that file, you can use gpg -c --armor message.txt This will generate an 'message.txt.asc', which is the same as the generated by the command before, but base64 coded, i.e., the encrypted file in text mode (.asc, not binary as .gpg would be).

II. Using a private key to encrypt a file

II.i. If you want to encrypt a file using your key, instead of only a passphare, use the command gpg -e -r 'yourname' message.txt. The argument 'yourname' should contain a part of the name that you used to create the private key. If you dont give the -r parameter, gpg will ask for it. You can type our name then (the same that you would type on command line).

II.ii. Point II.i would give you a binary file. If you want to get an ASCII file, use --armor. gpg -e -r 'yourname' --armor message.txt.

2. Decrypting the file encrypted with GPG

To decrypt, the file, use the command gpg -d --output OUTPUTFILE message.txt.gpg. This will ask for the passphrase and then decrypt the file message.txt.gpg to OUTPUTFILE, if the passphrase is correct. This passhrase is that which you used directly (point I., the -c parameter), or through your private key (point II., the -e parameter) This works for both binary (.gpg) or ascii (.asc) files. If you supress the --output FILE, it is outputted to console (stdout), then you can do this also, that is, redirect it to a file: gpg -d message.txt.gpg > OUTPUTFILE.txt Both do the same. 8 )

3

Try http://www.aescrypt.com/ it works great.

1

https://stackoverflow.com/questions/2811528/can-i-use-my-ssh-public-key-to-decrypt-a-file Is a question on a related subject. You can use the same principles for encryption if I am not mistaken.

0

For (GnuPG) 1.4.16

gpg -a --output outfile.txt --encrypt infile.txt

You will next be prompted:

Enter the user ID.  End with an empty line:

where the "user ID" can be found by running

gpg --list-keys

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.