Blockchain / Digital Health · September 6, 2024

Introduction to Cryptography

Cryptography, the science of securing communication and data from adversaries, has been an essential part of human history for millennia. In today’s digital age, it plays a pivotal role in protecting sensitive information from unauthorised access, ensuring the integrity of data, and safeguarding privacy. Whether it’s securing online transactions, communications between devices, or ensuring the authenticity of digital records, cryptography underpins much of our modern world. This article introduces the core principles of cryptography, its real-world applications, and its growing role in sectors such as healthcare, specifically in the UK.

Core Principles of Cryptography

At its foundation, cryptography is built upon a few core principles that guide its use in securing information:

1. Confidentiality

Confidentiality refers to keeping information secret from unauthorised parties. This is often achieved through encryption, where data is transformed into a format that is unreadable without the correct decryption key. Only authorised users with the correct key can access the information in its original form.

In practical terms, confidentiality ensures that sensitive data such as patient records, financial transactions, or personal communications remain private and only accessible to those who are supposed to have access.

2. Integrity

Integrity ensures that data has not been altered or tampered with during transmission or storage. Cryptographic techniques such as hashing are used to create a digital fingerprint of the data. If even a single bit of the data changes, the hash value will change, indicating potential tampering.

This is crucial in industries where data accuracy is paramount, such as healthcare, where even small changes to patient records could have serious consequences.

3. Authentication

Authentication is the process of verifying the identity of users, devices, or systems. In cryptography, this often involves digital signatures or certificates, which provide assurance that the person or system is who they claim to be. For instance, when logging into a secure system or website, authentication ensures that the user is legitimate and not an attacker attempting to gain unauthorised access.

In healthcare, authentication is vital to ensure that only authorised personnel can access patient data, reducing the risk of data breaches or identity theft.

4. Non-repudiation

Non-repudiation ensures that once an action has been taken, the entity responsible cannot deny having performed it. This is often achieved through digital signatures, which provide evidence that a particular user signed a document or authorised a transaction. This principle is particularly important in legal and financial contexts, where accountability is crucial.

In healthcare, non-repudiation can play a critical role in ensuring that doctors, nurses, and other healthcare professionals can be held accountable for actions such as authorising treatments or accessing sensitive patient information.

Types of Cryptography

There are several different types of cryptographic algorithms, each designed to address different security needs. The most common include:

1. Symmetric-Key Cryptography

In symmetric-key cryptography, the same key is used for both encryption and decryption. This approach is fast and efficient, making it ideal for encrypting large amounts of data. However, the challenge lies in securely sharing the key between the sender and the recipient, as anyone with the key can decrypt the data.

2. Asymmetric-Key Cryptography

Asymmetric-key cryptography, also known as public-key cryptography, uses a pair of keys: a public key for encryption and a private key for decryption. This system solves the key distribution problem, as the public key can be shared openly without compromising security. Only the holder of the private key can decrypt the information.

Asymmetric cryptography is widely used in applications such as digital signatures, secure email, and online transactions, providing a higher level of security than symmetric systems.

3. Hash Functions

A hash function is a one-way cryptographic algorithm that takes an input (or message) and returns a fixed-length string of characters. The output, called a hash value or digest, is unique to the input. Even the slightest change to the input will produce a drastically different hash value, making it a useful tool for verifying data integrity.

Hashes are commonly used in password storage, data integrity checks, and digital signatures.

Applications of Cryptography

Cryptography has numerous applications in the modern world, from securing online transactions to protecting government secrets. Some of the most common use cases include:

1. Secure Communication

One of the most well-known applications of cryptography is securing communications. Whether it’s email, messaging apps, or phone calls, encryption ensures that the content of the communication remains confidential and only accessible to the intended recipient.

2. Digital Signatures

Digital signatures provide a way to verify the authenticity and integrity of a message, document, or software. In the digital world, this is crucial for establishing trust, whether it’s verifying the sender of an email or ensuring that a downloaded software update is legitimate.

3. Secure Transactions

Cryptography is essential for securing financial transactions, from credit card payments to online banking. Encryption ensures that sensitive information such as credit card numbers and personal details are transmitted securely over the internet, reducing the risk of fraud and identity theft.

4. Blockchain and Cryptocurrencies

Cryptography underpins blockchain technology, which is the foundation for cryptocurrencies such as Bitcoin. Blockchains use cryptographic techniques to ensure the integrity of transactions, prevent double-spending, and secure the decentralised nature of the network.

Cryptography in the UK Healthcare System

In the UK, healthcare is a critical sector where cryptography plays a key role in ensuring the security and privacy of patient data, as well as enhancing operational efficiency. With the increasing digitisation of medical records and the growing importance of secure communications, cryptography has become more important than ever.

1. Protecting Patient Data

The NHS (National Health Service) in the UK handles vast amounts of sensitive patient information, including medical records, diagnoses, and personal details. Ensuring the confidentiality, integrity, and availability of this data is critical. Cryptographic techniques such as encryption and secure access controls are used to protect patient data, both at rest (when stored) and in transit (when transmitted between systems).

This is particularly important given the rise of cyberattacks on healthcare institutions, where attackers seek to steal patient data for financial gain or to disrupt operations. Cryptography provides the necessary tools to mitigate these risks and ensure that patient information remains confidential and secure.

2. Securing the Supply Chain

In the healthcare sector, the supply chain is a complex network of suppliers, manufacturers, distributors, and healthcare providers. Ensuring the integrity and authenticity of medical supplies, pharmaceuticals, and equipment is vital to patient safety. Cryptographic techniques such as digital signatures and blockchain technology can be used to track and verify the origin, authenticity, and condition of products as they move through the supply chain.

For example, blockchain technology can be used to create a tamper-proof record of every step in the procurement process, from the manufacturer to the hospital. This can help prevent fraud, counterfeit products, and ensure that the right medical supplies are delivered to the right place at the right time.

3. Procurement Security

Procurement in healthcare involves purchasing a wide range of goods and services, from medical equipment to IT services. Cryptography plays an important role in ensuring the security of procurement processes, protecting sensitive information such as supplier bids, contracts, and financial data from unauthorised access.

By using encryption, secure authentication methods, and digital signatures, the procurement process can be made more secure, reducing the risk of fraud, corruption, and data breaches.

Cryptography is an essential tool in the modern world, providing the means to protect sensitive information, ensure the integrity of data, and secure communications. Its applications are vast, spanning industries such as finance, government, and healthcare. In the UK healthcare system, cryptography plays a crucial role in protecting patient data, securing the supply chain, and safeguarding procurement processes. As technology continues to evolve, the importance of cryptography in ensuring security and privacy will only continue to grow.

 

Here is a basic example with python

from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
import os
import base64

# Function to generate a key from a password
def generate_key_from_password(password, salt):
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
        backend=default_backend()
    )
    key = kdf.derive(password.encode())
    return key

# Function to encrypt a message
def encrypt_message(plain_text, password):
    # Generate a random salt
    salt = os.urandom(16)
    
    # Generate the encryption key from the password
    key = generate_key_from_password(password, salt)

    # Generate a random initialization vector (IV)
    iv = os.urandom(16)
    
    # Initialize the AES cipher in CBC mode
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    encryptor = cipher.encryptor()

    # Pad the plain text to be a multiple of the block size (16 bytes for AES)
    padder = padding.PKCS7(algorithms.AES.block_size).padder()
    padded_data = padder.update(plain_text.encode()) + padder.finalize()

    # Encrypt the padded data
    encrypted_message = encryptor.update(padded_data) + encryptor.finalize()

    # Return the salt, IV, and encrypted message, all base64-encoded for convenience
    return base64.b64encode(salt + iv + encrypted_message).decode()

# Function to decrypt a message
def decrypt_message(encrypted_message, password):
    # Decode the base64-encoded encrypted message
    encrypted_message = base64.b64decode(encrypted_message)

    # Extract the salt, IV, and actual encrypted message
    salt = encrypted_message[:16]
    iv = encrypted_message[16:32]
    encrypted_message = encrypted_message[32:]

    # Generate the key using the password and extracted salt
    key = generate_key_from_password(password, salt)

    # Initialize the AES cipher in CBC mode for decryption
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    decryptor = cipher.decryptor()

    # Decrypt the encrypted message
    padded_data = decryptor.update(encrypted_message) + decryptor.finalize()

    # Remove the padding
    unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
    plain_text = unpadder.update(padded_data) + unpadder.finalize()

    return plain_text.decode()

# Example usage
if __name__ == "__main__":
    password = "my_secret_password"
    message = "This is a confidential message."

    print("Original message:", message)

    # Encrypt the message
    encrypted = encrypt_message(message, password)
    print("Encrypted message:", encrypted)

    # Decrypt the message
    decrypted = decrypt_message(encrypted, password)
    print("Decrypted message:", decrypted)

Here’s a baic script in Python that demonstrates how to implement a simple cryptography solution using symmetric encryption (AES) from the cryptography library. The script will show how to encrypt and decrypt a message, ensuring confidentiality, one of the core principles of cryptography.

First, you’ll need to install the cryptography package if you haven’t already. You can install it via pip:

pip install cryptography

Here’s a Python script that implements AES encryption and decryption:

python

How It Works:

  1. Key Derivation:
    • The PBKDF2HMAC key derivation function (KDF) generates a strong encryption key from the provided password and a random salt.
    • A salt ensures that even if two users have the same password, they’ll get different encryption keys.
  2. Encryption:
    • The AES (Advanced Encryption Standard) algorithm in CBC (Cipher Block Chaining) mode is used to encrypt the message.
    • A random IV (Initialization Vector) is generated for each encryption to ensure that even if the same message is encrypted multiple times, the output will be different.
    • The message is padded using PKCS7 padding, as AES works on blocks of fixed size (16 bytes for AES).
  3. Decryption:
    • The salt and IV are extracted from the encrypted message and used to regenerate the encryption key and set up the cipher for decryption.
    • The padding is removed from the decrypted message to return the original plain text.

Example Output:

Original message: This is a confidential message.
Encrypted message: <some long encrypted string>
Decrypted message: This is a confidential message.

This script demonstrates the basic workings of cryptography, showing how symmetric encryption can be used to protect a message. You can adapt this code to integrate it into larger systems, such as securing data transmissions or storing encrypted sensitive information.