cryptography Getting started with cryptography Introduction


Cryptography is the science of using mathematical constructs (codes) to make communication secure. The field of cryptography is a subset of the field of Information Security.

There are many cryptographic operations possible; some best known examples are:

  • Encryption : transforming a plaintext message into a ciphertext message so that the the message remains confidential
  • Decryption : transforming a ciphertext message back into a plaintext message
  • Secure hashing : performing irreversible (one-way) compression to create a statically sized, computationally distinct representation for a specific message.

Cryptography is based on math, and arithmetic is frequently used in algorithms related to cryptography. There is a small subset of primitives, schemes and protocols that are used by developers. Developers usually do not implement the algorithms themselves but use the schemes and protocols provided by cryptographic API's and runtimes.

A primitive could be a block cipher such as AES. A primitive is any algorithm that is used as building block for a cryptographic scheme. A scheme is for instance a block cipher mode of operation such as CBC or GCM. One or more cryptographic schemes can make up a cryptographic protocol. A protocol such as TLS uses many cryptographic schemes, but also message encoding / decoding techniques, message ordering, conditions for use etc. Low level cryptographic API's just provide direct access to primitives while high level API's may offer access to full protocol implementations.

Messages have been encrypted and decrypted by hand since written word was invented. Mechanical devices have been used at least since ancient Greek society. This kind of cryptography is referred to as classic cryptography. Many introductions to cryptography start with classic cryptography as it is relatively easy to analyze. Classic algorithms however do not adhere to the security required from modern constructs and are often easy to break. Examples of classic schemes are the Caesar and Vigenère. The most well known mechanical device is undoubtedly the Enigma coding machine.

Modern cryptography is based on science - mainly math and number/group theory. It involves much more intricate algorithms and key sizes. These can only be handled efficiently by computing devices. For this reason modern cryptography mainly uses byte oriented input and output. This means that messages need to be converted to binary and back before they can be transformed by any implementation of a cryptographic algorithm. This means that (textual) messages need to be transformed using character-encoding before being encrypted.

Forms of character-encoding of textual messages is UTF-8. Structured messages may be encoded using ASN.1 / DER or canonical XML representations - or any number of proprietary techniques. Sometimes the binary output needs to be transformed back into text as well. In this case an encoding scheme such as base 64 or hexadecimals can be used to represent the binary data within text.

Cryptography is notoriously hard to get right. Developers should only use constructs that they fully understand. If possible, a developer should use a higher level protocol such as TLS to create transport security. There is no practical chance of creating a secure algorithm, scheme or protocol without formal education or extensive experience. Copy/pasting examples from the internet is not likely lead to secure solutions and may even result in data loss.