Skip to main content

1.0 General Security Concepts

1.4 - Encryption Keys


Learning Objectives

1.4 - Explain the importance of using appropriate cryptographic solutions.

  • Key length
  • Key exchange

What Are Encryption Keys?

Encryption keys are fundamental components of cryptographic systems. These keys, typically composed of a string of characters, are used to encrypt and decrypt data, ensuring that only authorised parties can access the information. An encryption key works in conjunction with an algorithm to transform readable plaintext into unreadable ciphertext and vice versa. The security of encrypted data largely depends on keeping the encryption keys private and secure, as these keys are the only means through which encrypted data can be deciphered back into its original form.

Encryption keys can be categorised based on the type of encryption:

  • Symmetric Keys: A single key is used for both encryption and decryption. This key must be shared among parties through secure channels to maintain confidentiality.
  • Asymmetric Keys: Comprises a pair of keys - a public key for encryption and a private key for decryption. The public key can be shared openly, while the private key must remain confidential to the owner.

Why is it Important to protect Encryption Keys?

Encryption algorithms and all of the inner workings of their mathematical formulas are usually public for all to see, this is what makes them trustworthy.

Further, there is very little that isn't known about the overall encryption process. Attackers can know the algorithm, the key size used, and they may even intercept the encrypted output of your data. Despite all this, they cannot* reverse the encryption process without knowing your encryption key.

This is why it is critical to protect your private keys, because if anyone gains access to it they can decrypt all of your data! Essentially the encryption key is the only part of the encryption process that is actually protecting your data.

* Important Note

It is important that you use an encryption algorithm that meets current industry standards and is not vulnerable or deprecated. If you use an outdated algorithm, with a short key length or other vulnerabilities, attackers may be able to break this encryption.

Additionally, as computational efficiency is further developed, such as with the development of quantum computers, encryption that is currently considered secure may no longer be safe to use in the future.

Therefore it is more accurate for me to say that "they cannot currently reverse the encryption process without knowing the cryptographic key, due to the infeasibility of the mathematical and computational power required."

Do not worry! Quantum resistant encryption is currently in development and will likely be available before a functional quantum computer is created!

Key Lengths

The length of an encryption key is a significant factor in the security of an encryption system. Longer keys generally provide higher security as they increase the difficulty for attackers attempting to break the encryption through brute-force attacks (e.g. Trying every possible key combination!).

Therefore, the size of the key must be large enough to make the time and resource cost of a brute force attack ludicrous.

Symmetric Key Lengths:

Symmetric keys commonly range from 128-bits to 256-bits. While 128-bit keys are considered secure for most applications, 256-bit keys provide an additional security buffer and are preferred for highly sensitive data.

Even still, some estimates show that the time required to brute-force every possible combination of an AES 128-bit key would take many multiple times longer than the known age of the universe!

Asymmetric Key Lengths:

Asymmetric keys typically need to be longer due to the nature of the algorithms being used. For example, RSA keys are typically between 1024 and 4096 bits. This is because, asymmetric keys are mathematically related and typically have an internal structure which limits the amount of valid key possibilities. This limitation of valid possibilities, would allow attackers to attempt to shorten their list of brute force attempts and would decrease the time it takes to crack the key.

This is why asymmetric algorithms such as RSA typically have much longer key lengths. However, there are multiple exceptions to this rule, some asymmetric algorithms such as ECC (Elliptic Curve Cryptography) use keys as short as 192-bits while still offering comparable security to RSA.

What is Key Exchange?

Key exchange refers to the method by which cryptographic keys are securely shared between authorised parties. Without a secure key exchange mechanism, encrypted data can become compromised. This is especially important when using symmetric keys, due to their requirement for confidentiality, as the same key is used for both encryption and decryption.

Effective key exchange mechanisms ensure that keys are shared securely, protecting the confidentiality and integrity of the data. This is usually achieved through two methods:

  • Out-of-Band Key Exchange: Keys are exchanged through secure, non-digital methods such as face-to-face meetings, courier services, or telephonic communications. This minimises the risk of interception during transmission.
  • In-Band Key Exchange: Keys are shared over networks. To ensure security, symmetric keys are typically encrypted with asymmetric encryption. For example, one party encrypts a session key with the other's public key, ensuring that only the recipient can decrypt it using their private key.

Real-time applications often use asymmetric encryption to establish and share a temporary symmetric key (session key) for encrypting data efficiently. This allows the symmetric key to be securely shared and used for the duration of the session, after which it is discarded or replaced.

Types of Key Exchange Mechanisms

Here are two examples of popular key exchange methods and how they work:

1. Diffie-Hellman Key Exchange

The Diffie-Hellman (DH) key exchange is one of the earliest and most widely used cryptographic protocols for secure key exchange. It allows two parties to jointly establish a shared secret over an unsecured communication channel without transmitting the key itself. Here's how it works:

  1. Both parties agree on a large prime number (p) and a base generator (g), which are not secret and can be shared publicly.
  2. Each party selects a private key (a or b), which is kept secret, and generates a public key by raising the generator to the power of their private key modulo the prime number. (e.g. Public Key A = ga mop p)
  3. The parties exchange their public keys over the network.
  4. Each party then raises the received public key to the power of their private key modulo the prime number. Both parties arrive at the same shared secret, which can then be used as a symmetric encryption key. (e.g. Ab mod p == Ba mod p)

Diffie-Hellman is commonly used in protocols like TLS (Transport Layer Security), SSH (Secure Shell) and IPSec (IP Security) to establish secure communications.

2. RSA Key Exchange

RSA, while primarily associated with encrypting data and digital signatures, can also be used for key exchange. Here's a simplified version of how RSA key exchange works:

  1. The recipient generates a pair of RSA keys: a public key and a private key. The public key can be freely distributed, while the private key remains confidential.
  2. The sender encrypts a symmetric session key using the recipient's public key and sends it over the network.
  3. The recipient uses their private RSA key to decrypt the encrypted session key.
  4. Once decrypted, the symmetric session key is used for secure communication between the parties.

RSA key exchange is often used to securely establish a temporary symmetric key, which is then used for real time data encryption in transit during a session.

Mathematical Example of a Diffie-Hellman Exchange

Diffie-Hellman Exchange Method

As seen in the image above, both Jesse and Walter have independently computed the same shared secret key (s=2) without ever transmitting it directly over the insecure channel! This shared secret can be used as a symmetric key for encrypting further communications. The security of the Diffie-Hellman exchange is rooted in the difficulty of computing discrete logarithms, making it challenging for an eavesdropper to determine the shared secret from the public values alone.

💡
If you're a Premium member, you can login and use the interactive quiz below to test your knowledge of this lesson!