<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE artikkel PUBLIC "-//infoweb.ntnu.no//DTD Infoweb 1.0//NO"
"http://infoweb.ntnu.no/infoweb.dtd">

<artikkel spraak="en">
  <tittel>Cryptography and PGP</tittel>
  <forfatter>grip</forfatter>
  <sammendrag>General information about encryption and the use of PGP/GnuPG</sammendrag>

<hoveddel>

<os2>Some information about cryptography</os2>
<avsnitt>
  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.
</avsnitt>

<os3>Conventional cryptography</os3>
<avsnitt>
  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.
</avsnitt>

<os3>Public key</os3>

<avsnitt>
  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.
  
</avsnitt>

  <ul>
  <li>If A doesn't already have B's public key, he needs to obtain it. It can, for instance, be sent to
  him in an unencrypted email, or be put out on B's homepage on the web and collected from there.</li>
  <li>A encrypts the email with B's public key, and sends it to B. Third parties that might intercept
  the transmission can not decrypt the email, even if they posess B's <kursiv>public</kursiv> key.</li>
  <li>When B receives the email, he decrypts it using his private key.
</li>
  </ul>

<avsnitt>
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.
</avsnitt>

<os3>Digital signatures</os3>

<avsnitt>
  A digital signature is an analogy to a regular, phyiscal signature. When you sign something digitally,
  the <kursiv>private</kursiv> key is used to make the signature. The signature can then be read by the
  recipient using the <kursiv>public</kursiv> 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.
</avsnitt>

<os3>Certificates</os3>

<avsnitt>
  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.
</avsnitt>

<os3>Fingerprints</os3>

<avsnitt>
  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.
</avsnitt>

<os2>PGP</os2>
<avsnitt>
  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 <ekstern
  uri="http://www.pgpi.org">here</ekstern>.
</avsnitt>

<os3>The principles behind PGP</os3>

<avsnitt>
  PGP is a combination of several technologies.
</avsnitt>

<ul>
<li>First the information is compressed, to lessen the size and minimize repetitions.</li> 
<li>A random session key is made based on unpredictable values, like the time between your key strokes
or the movement of the mouse. This key is used only once. The next time you encrypt something, a new key
is generated. Because of this, encryption of the same information twice, using the same key,  will
yield a completely different result.</li>

<li>The session key is an encryption key used to encrypt the information with a conventional,
<kursiv>symmetrical</kursiv> algorithm. The reason for this is that symmetrical encryption is much faster
than encryption with a public key.</li>
<li>The session key is encrypted with the recipient's public key, and added to the already encrypted
information. In this way, only the recipient can retrieve the symmetrical key used in the encryption,
and thereby decrypt the information.</li>
<li>Finally, the information is signed. The signature, however, is not generated based directly on the
information that has been encrypted, because that would potentially take up much space, and a lot of
time. Instead, a hash of the information is generated, and the signature is made based on this. This
works because if the information is changed by one bit, the hash is also changed and the signature is
invalid.
</li>
</ul>

  
<os2>Using PGP</os2>

<avsnitt>
  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.
</avsnitt>

<avsnitt>
  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
  <kommando>pgp</kommando> (PGP) or <kommando>gpg</kommando> (GnuPG) with different arguments. For an
  overview of common commands, use <kommando>pgp -h</kommando> or <kommando>gpg -h</kommando>. The first
  thing you would normally do is to <uthev>create your own key pair</uthev>. To do this, you type:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -kg

    For GnuPG:
    $ gpg --gen-key
  </konsoll>
</avsnitt>

<avsnitt>
  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 <kommando>.pgp</kommando> or the
  <kommando>.gnupg</kommando> 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.
</avsnitt>

<os3>A little test</os3>
<avsnitt>
  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:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -es pgptest "user-id"

    For GnuPG:
    $ gpg -es -r "user-id" pgptest
  </konsoll>
</avsnitt>

<avsnitt>
  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
  <kommando>pgptest.pgp</kommando>, which contains the contents of <kommando>pgptest</kommando>
  encrypted with the recipient's (your) public key, and signed with your private key. Type:
</avsnitt>

<avsnitt>
  <konsoll>
    $ cat pgptest.pgp
  </konsoll>
</avsnitt>

<avsnitt>
  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:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -esa pgptest

    For GnuPG:
    $ gpg -esa -r "user-id" pgptest
  </konsoll>
</avsnitt>

<avsnitt>
  If you now look at the contents of the file <kommando>pgptest.asc</kommando>, you see the encrypted
  version of the file in a better format for email communication. Now you may try to <uthev>decrypt the
  file</uthev> again by typing:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp pgptest.asc

    For GnuPG:
    $ gpg pgptest.asc
  </konsoll>
</avsnitt>

<avsnitt>
  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 <kommando>pgptest</kommando> already, and ask you
  for a new file name. Type, for instance, <kommando>pgptest2</kommando>, and take a look at the contents
  when the program finishes. It contains the exact same information as the original
  <kommando>pgptest</kommando>. The program also confirms the signature on the file.
</avsnitt>

<os3>Key management</os3>
<avsnitt>
  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 <uthev>export your public key</uthev> to an ASCII file with the following
  command:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -kx "user-id" filename

    For GnuPG:
    $ gpg --export -a -o filename "user-id"
  </konsoll>
</avsnitt>

<avsnitt>
  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 <uthev>add these</uthev> to your key ring with
  the following command:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -ka filename

    For GnuPG:
    $ gpg --import filename
  </konsoll>
</avsnitt>

<avsnitt>
  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:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -kc "user-id"

    For GnuPG:
    $ gpg --check-sigs "user-id"
  </konsoll>
</avsnitt>

<avsnitt>
  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:
</avsnitt>

<avsnitt>
  <konsoll>
    For PGP:
    $ pgp -ks "user-id"
    
    For GnuPG:
    $ gpg --sign-key "user-id"
  </konsoll>
</avsnitt>

<avsnitt>
To show the <uthev>fingerprint</uthev> of a key, type:
</avsnitt>

<avsnitt>
<konsoll>
    For PGP:
    $ pgp -kvc "user-id"

    For GnuPG:
    $ gpg --fingerprint "user-id"
</konsoll>
</avsnitt>

<os3>Other functionality</os3>

<avsnitt>
  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 <kommando>man pgp</kommando> or <kommando>man gpg</kommando>.
</avsnitt>

</hoveddel>


</artikkel>
