Monday, April 20, 2015

GPG common commands

To create a key:
gpg --gen-key
generally you can select the defaults.

gpg --list-keys
list your available GPG keys that you have from other people.

gpg --list-keys your_email@address.com

gpg --list-secret-keys
To list the keys in your secret key ring.
to export a public key into file public.key:
gpg --export -a "User Name" > public.key
This will create a file called public.key with the ascii representation of the public key for User Name. This is a variation on:
gpg --export
which by itself is basically going to print out a bunch of crap to your screen. I recommend against doing this.
gpg --export -a "User Name"
prints out the public key for User Name to the command line, which is only semi-useful

to export a private key:
gpg --export-secret-key -a "User Name" > private.key

This will create a file called private.key with the ASCII representation of the private key for User Name.
It's pretty much like exporting a public key, but you have to override some default protections. There's a note (*) at the bottom explaining why you may want to do this.

to import a public key:
gpg --import public.key

This adds the public key in the file "public.key" to your public key ring.

to import a private key:
gpg --allow-secret-key-import --import private.key

This adds the private key in the file "private.key" to your private key ring. There's a note (*) at the bottom explaining why you may want to do this.

to delete a public key (from your public key ring):
gpg --delete-key "User Name"
This removes the public key from your public key ring.
NOTE! If there is a private key on your private key ring associated with this public key, you will get an error! You must delete your private key for this key pair from your private key ring first.

to delete an private key (a key on your private key ring):
gpg --delete-secret-key "User Name"
This deletes the secret key from your secret key ring.
To list the keys in your public key ring:

To generate a short list of numbers that you can use via an alternative method to verify a public key, use:
gpg --fingerprint > fingerprint
This creates the file fingerprint with your fingerprint info.


Encrypt Messages

You can encrypt messages using the "--encrypt" flag for GPG. The basic syntax would be:
gpg --encrypt --sign --armor name_of_file

The parameters basically encrypt the email, sign it with your private key to guarantee that it is coming from you, and generates the message in a text format instead of raw bytes.

You should also include a second "-r" recipient with your own email address if you want to be able to read the message ever. This is because the message will be encrypted with each person's public key, and will only be able to be decrypted with the associated private key.

So if it was only encrypted with the other party's public key, you would not be able to view the message again, unless you somehow obtained their private key. Adding yourself as a second recipient encrypts the message two separate times, one for each recipient.
Decrypt Messages

When you receive a message, simply call GPG on the message file:

gpg file_name
The software will prompt you as necessary.

If you have the message as a raw text stream, you can copy and paste it after you just typing gpg without any arguments. You can press "CTRL-D" to signify the end of the message and GPG will decrypt it for you.
gpg --edit-key
gpg --gen-revoke

Popular Posts

Labels

ad ( 5 ) Amazon ( 42 ) Answer ( 1 ) API ( 23 ) automation ( 1 ) blog ( 22 ) book ( 2 ) business ( 1 ) career ( 12 ) cdn ( 3 ) centos ( 1 ) cloud ( 125 ) CRM ( 24 ) current ( 15 ) data ( 16 ) database ( 65 ) design patterns ( 17 ) development ( 3 ) eCommerce ( 26 ) email ( 93 ) ETL ( 2 ) framework ( 3 ) git ( 11 ) google ( 181 ) IDE ( 18 ) Integration ( 1 ) interview ( 16 ) Java ( 407 ) Java EE ( 108 ) javascript ( 42 ) Jboss ( 4 ) JPA ( 51 ) JSF ( 44 ) linux ( 337 ) Marketing ( 21 ) mobile ( 45 ) model ( 1 ) MySQL ( 199 ) online money ( 16 ) OOP ( 7 ) open source ( 26 ) performance ( 72 ) php ( 51 ) python ( 46 ) quality ( 6 ) referral ( 3 ) restful ( 23 ) security ( 137 ) SEO ( 19 ) social ( 27 ) software ( 75 ) spam ( 4 ) Spring ( 1 ) SQL ( 22 ) system ( 33 ) testing ( 17 ) tool ( 96 ) UML ( 8 ) virtual ( 10 ) web ( 234 ) web services ( 14 ) WildFly ( 5 ) wordpress ( 12 )