www.ntnu.no *
INFOWEB >  security >  encryption  > Cryptography and PGP
Tasks
You may add comments
Or e-mail this article
Read articles written by thomasan
User rating
How much did this article help you?
Much Some Little
Print preview
You do not need a 'printer-friendly page' to print this page. Here's why
Contents

Cryptography and PGP

Some information about cryptography

The purpose of cryptography is the transmission of information between two parties, where only the sender and the recipient can understand the contents. This is achieved by the sender transforming the original information into meaningless, "cryptic" information, so that it makes no sense to anyone that might want to intercept the transmission. However, the information must be readable by the recipient. Therefore, the coding of the information into meaningless gibberish, and the decoding back to the original information is achieved through a cryptographic algorithm, that utilizes one or more cryptographic keys. These are decided upon by the involved parties. Both the sender and the recipient have a key that is used respectively for encryption and decryption of the information.

Conventional cryptography

The traditional, conventional form of cryptography is so-called symmetrical, which means that the sender and the recipient are in possession of the same information. In using keys, this is also called secret key cryptography. The sender uses the key to encrypt the information, and the receipient uses the very same key to decrypt it again. Several symmetrical encryption algorithms are widely used. The most well known is the DES algorithm (Data Encryption Standard), developed by IBM in the seventies. This type of encryption has one major problem. The encryption key must be kept secret, but it must also be communicated between the parties that intend to use it, without being exposed. If the key itself is compromised, the encryption is without any value, and if anything it merely provides a false sense of security. With the key, third parties can both understand the information that is exchanged, and send out false information encrypted with the key.

Public key

A modern form of cryptography is so-called public key cryptography. Widely used encryption algorithms of this type are RSA, DH and DSA. With this type of cryptography, the sender and the recipient are in posession of different keys. Each person who wishes to exchange encrypted information generates his or her own set of keys, which consists of one private key, and one public key. The public key is distributed freely among everyone you wish to exchange information with. It does not matter if this key is compromised, because the public key can only be used for encryption, not for decryption. To decrypt the contents back to its original form, you need the private key, which only the owner of the set of keys is in posession of. An exchange of information will therefore be conducted like this, if A wants to send and email to B.

This form of cryptography is ultimatly based on large primary numbers, and the fact that, with the knowledge one has today, it is very much harder to factor a product of large primary numbers than to multiply them to generate the product in the first place. It has not been mathematically proven that it has to be this way, but so far it's proven to be in practice. If you wish to crack an encryption of this kind, you need to factor, to come up with the original numbers. This mathematical link between the public and the private key makes it theoretically possible to deduce the private key, with the knowledge only of the public one. But it requires enourmous computing power and a long time. In reality, so much so that it can't be done in any forseeable future. How hard it is to crack the encryption relies entirely on the magnitude of the numbers used. Therefore, the strength of the encryption is commonly "measured" in number of bits. The more bits, the more computing power is required to crack it. Conventional cryptography is also based on large numbers, but this type of cryptography does not require nearly as large numbers as public key cryptography for it to be equally strong.

Digital signatures

A digital signature is an analogy to a regular, phyiscal signature. When you sign something digitally, the private key is used to make the signature. The signature can then be read by the recipient using the public key, pretty much opposite of the actual encryption. If the signature can be read by the public key, it must be made with its private counterpart, and this confirms the sender's identity. The signature is created based on what is signed, in addition to the private key. Hence, the signature can't be separated from its context, making it impossible to extract the signature from one document and using it on another.

Certificates

One obvious problem with the public key principle is that, unless you are handed the key in person by the owner himself, you can never be quite sure if you have received the right key, and not a forgery. This is the reason why public keys are distributed with a digital certificate. For all practical purposes, this consists of information about the owners identity (like his name and email address), and one or more digital signatures confirming the connection between the identity and the key itself. The whole system is based on trust. The certificate must be signed by someone the recipient trusts, an authority. The recipient can then choose to believe that this authority is serving the truth, through the digital confirmation. For this to work, the recipient needs to already be in possession of the authority's public key, enabling him to read the signature. Some companies make a living out of offering their guarantees through such certificates.

Fingerprints

Another way of checking the authenticity of a public key is through so-called fingerprints. A fingerprint is a so-called hash of the key. The hash is generated by a one-way hash function, which returns information of a certain size, even if the argument is of variable size. The hash function is constructed such that if the argument is changed, so is the hash, regardless of the significance of the change, even in the largest possible arguments the hash function receives. It is not possible to reverse this process and arrive at the original information using the hash. A fingerprint is a hash of a public key, which is relatively small and easy to read. This can be used if you, for instance, know the owners voice and can get in touch with him on the phone. The owner then has the fingerprint generated on his side, and you can compare them.

PGP

PGP stands for Pretty Good Privacy and was originally developed by the American Philip R. Zimmermann as a freeware product. It is now the most widely used enryption software for email in the world. PGP is now a commercial product, but is distributed for free for non-commercial purposes. PGP is for all practical purposes the name of a protocoll for encrypted information, signatures and certificates for the exchange of public keys, as defined in the OpenPGP standard. A free program that follows this standard is GnuPG (Gnu Privacy Guard). You may download PGP products for different platforms here.

The principles behind PGP

PGP is a combination of several technologies.

Using PGP

Here follows a small guide on how to use PGP, based on a command-line interface. For different programs/versions, the syntax will vary, but the principles are the same. Here, some simple commands for PGP version 6.5.8 and GnuPG version 1.2.1 for Unix are presented.

If you don't have the program already installed, you need to do this. Instructions for this are enclosed when you download the product. When it has been installed, it is used by running the program pgp (PGP) or gpg (GnuPG) with different arguments. For an overview of common commands, use pgp -h or gpg -h. The first thing you would normally do is to create your own key pair. To do this, you type:

konsoll #1
    For PGP:
    $ pgp -kg

    For GnuPG:
    $ gpg --gen-key
  

Follow the instructions and answer the questions that are asked. You should make keys for the DSS/DH-algorithms (called DSA/ElGamal in GnuPG). In PGP you first have to choose to make a signature key, and then answer yes to the question of whether you want to make an encryption key to go with it. When the program is done, it has created a set of keys which are yours. It has also created a public and a secret "key ring", which is stored in the .pgp or the .gnupg directory on your home area. These contain your own keys, and the public key ring will also contain the keys you eventually receive from others, which you need for encrypting information for them.

A little test

You now have everything you need to start encrypting. You don't, however, have any other public keys than your own (yet), but to see how things work you can encrypt something with it, and decrypt it again with your private key. Type:

konsoll #2
    For PGP:
    $ pgp -es pgptest "user-id"

    For GnuPG:
    $ gpg -es -r "user-id" pgptest
  

where user-id is the user id (normally name and/or email-address) for the person that will be receiving the encrypted information. In this case it is you, so type your own user id, which you chose during the creation of the keys. If you set a pass phrase on the secret key (recommended), you wil be asked to type this, because it is used for the signature. The program will now create a file called pgptest.pgp, which contains the contents of pgptest encrypted with the recipient's (your) public key, and signed with your private key. Type:

konsoll #3
    $ cat pgptest.pgp
  

to see the contents of the file. As you can see, the encrypted version is not understandable, but it is not in a very good format for emailing to someone either. To encrypt it and store it with reguler ASCII-characters, you can add an "a" in the option list:

konsoll #4
    For PGP:
    $ pgp -esa pgptest

    For GnuPG:
    $ gpg -esa -r "user-id" pgptest
  

If you now look at the contents of the file pgptest.asc, you see the encrypted version of the file in a better format for email communication. Now you may try to decrypt the file again by typing:

konsoll #5
    For PGP:
    $ pgp pgptest.asc

    For GnuPG:
    $ gpg pgptest.asc
  

If you set a pass phrase, you will again be asked for it, to decrypt with your private key. The program will protest and say there is a file called pgptest already, and ask you for a new file name. Type, for instance, pgptest2, and take a look at the contents when the program finishes. It contains the exact same information as the original pgptest. The program also confirms the signature on the file.

Key management

What we have done so far works very nicely if you only plan to exchange information with yourself. If you, however, want other people to encrypt information for you, you have to be able to distribute your public key. You may export your public key to an ASCII file with the following command:

konsoll #6
    For PGP:
    $ pgp -kx "user-id" filename

    For GnuPG:
    $ gpg --export -a -o filename "user-id"
  

where user-id is your user id, and filename is the name of the file you want the key to be written to. You may now distribute this file to those who need to send you encrypted information. Similarly, you will receive other's public keys, and you may add these to your key ring with the following command:

konsoll #7
    For PGP:
    $ pgp -ka filename

    For GnuPG:
    $ gpg --import filename
  

where filename is the file with the key in it. When you have added it you may check if any of the signatures on the key are known, by typing:

konsoll #8
    For PGP:
    $ pgp -kc "user-id"

    For GnuPG:
    $ gpg --check-sigs "user-id"
  

If the key is signed by someone you trust, you may choose to accept this as proof of the keys authenticity. You may yourself sign other people's public keys with the following command:

konsoll #9
    For PGP:
    $ pgp -ks "user-id"
    
    For GnuPG:
    $ gpg --sign-key "user-id"
  

To show the fingerprint of a key, type:

konsoll #10
    For PGP:
    $ pgp -kvc "user-id"

    For GnuPG:
    $ gpg --fingerprint "user-id"

Other functionality

These are the most basic commands, and the mimimum for being able to exchange information with others using PGP/GnuPG. There are other possibilities that are not mentioned here. You may for instance set a trust level on different people in your key ring. It is recommended to look through the manual pages of the program, using the command man pgp or man gpg.


Languages: en flag_no Comments: 0 Aid: 231 User rating:
 
 
Last updated: 2006-07-13 Author: thomasan Read: 3972 times