Tuesday, 24 November 2015

Decrypting and encrypting messages with gpg in linux (ubuntu)

Encrypting and decrypting files with gpg tool is quite easy:
>gpg --recipient Ben --encrypt test.txt
>gpg --decrypt test.txt.gpg

But if you don't want to create a file and just need to encrypt or decrypt a message quickly?

This workflow will work

Encrypt with your gpg key for some known recipient:
>gpg --armor --encrypt --recipient bend
It might prompt you to type a password for your key at this stage.
Now type your message in and here goes the tick: press CTRL+D, which means the end of a input!
After that it will print your encrypted message into standard output.
Shortcut for the command above:
>gpg --aer bend

Encrypt symmetrically with some passphrase:
>gpg --armor --symmetric
It will prompt you to type a passphrase for symmetric encryption
Now type your message in and press CTRL+D
>gpg -ac

Decrypt some pgp message:
>gpg --decrypt
Paste your pgp message, for example:
Version: GnuPG v1

Type your passphrase (for example 123 for this symmetric message) or a password to your gpg key if it is encrypted for you as a recipient.
And again press CTRL+D to see decrypted message.