Thursday, January 29, 2009

GPG (PGP) Public/Private Key Encryption/Decryption/Signing using the Command Line

I've had a couple emails asking about public/private key security and how you can perform this task without the need for GUI-based applications. Below you will see an example command line session of mine showing the complete process from plain text to cipher and back to plain text.
Macintosh:Desktop chris$ cat test.txt
This is a test secret message.
Macintosh:Desktop chris$ gpg -sea -r 'Christopher M. Ball' test.txt 

You need a passphrase to unlock the secret key for
user: "Christopher M. Ball <chris.m.ball@gmail.com>"
1024-bit DSA key, ID 0B9FD4CE, created 2007-11-01

Macintosh:Desktop chris$ cat test.txt.asc 
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.8 (Darwin)

hQIOA5PL0Y5P2m2zEAf/b+o5ISTGorJnloGYyAnmt4hw17r98MZ57IFOB/AAJ4hG
Sp/Ru72+0qhEW/IbsX+i4bLO7bAyoPY47yw549yALP621O6s+mqrisrC0nJ33N8v
smyJ8sROn+Pzf53Xkf41wmTgssgSZAd3B60wrmf+AW0csHfjWAd6n8h9lw53HwfR
uzvG3CIkElo6eTG447qGXW07e7AbjlFRAOuuzn9YgvDLHHbpYM38o/snufOOkejD
lyeUQTVwOOxNa4nAQJYSO6Xwd9YP7+MsntbR598DsA5xLRlXxZsEplkoE3c0hRDh
3PCcIeBDUaXC7ZLDc/on7CrL5S7NJUEKGeAx7GMgOgf/QClLSBkMYrO31wbGd4ga
27YLUJNNdGRXIGHsJy/03OGYPh1tKS7xXYJd6q2oK1t9qlyWKTmBLLndIa3UvslF
MVsz7tLqKwr873lBWwdpNBS9YQiBNjqVwNyh4S3XVzzb8RsAa9WSRO2WGqOGaktf
VsfwDdVFmrNwu57f24U2TYzAUWaij/W/e3ANwor6FpvNva8AT9yO0d5xz+PYRXrw
n9UkPQR12TAZ94bcDWq0VWp/yJp+9zMT0MY/kilq4eQxaX6Ha3MtRz+GX7OizK9a
VdSly/AC4RHFVqbK1qhhq8U2Uu7ce0DUs9NYc0DxcoGzz28KFv2RGekh1Pbo+Lx/
j9KxAeL0+F+sdeojxktqmtG1Lp+z1TKrQ69VhQlSOT+kjMH/UfUqjMmCsA9v8t7Q
xRA+AK00K6FWV/x8AcG5ypTeq3DeWLrHLfdB6Ct8iA3yUF8qIGH60jRyXpY/jIL+
pJ7mxNcBQS33RNuoI2eOok5+aAZZERM1DRJKEzJN+PQf8YKG/ZesCRzGO1Di6sgB
J3o/JKnvrGyuXDZ8cmLHvajXk8hKAvQdvKmRl5rMnLiuP2/B
=i0iO
-----END PGP MESSAGE-----
Macintosh:Desktop chris$ rm test.txt
Macintosh:Desktop chris$ gpg test.txt.asc 

You need a passphrase to unlock the secret key for
user: "Christopher M. Ball <chris.m.ball@gmail.com>"
2048-bit ELG-E key, ID 4FDA6DB3, created 2007-11-01 (main key ID 0B9FD4CE)

gpg: encrypted with 2048-bit ELG-E key, ID 4FDA6DB3, created 2007-11-01
      "Christopher M. Ball <chris.m.ball@gmail.com>"
gpg: Signature made Thu Jan 29 08:41:07 2009 PST using DSA key ID 0B9FD4CE
gpg: Good signature from "Christopher M. Ball <chris.m.ball@gmail.com>"
Macintosh:Desktop chris$ cat test.txt
This is a test secret message.

We typically do not send messages to ourselves, but this example shows the basic practice. In a future posting I will put together a similar simple example of how to generate your private/public key pairs using the command line, so stay tuned.

Cheers,
Chris

0 comments: