Cryptography
Cryptography
Encryption is used on the Internet to transmit data, such as payment information, e-mails, or
personal data, confidentially and protected against manipulation. Data is encrypted using
various cryptographic algorithms based on mathematical operations. With the help of
encryption, data can be transformed into a form that unauthorized persons can no longer read.
Digital keys in symmetric or asymmetric encryption processes are used for encryption.
We can distinguish between symmetric and asymmetric encryption techniques
Symmetric Encryption:
Symmetric encryption, also known as secret key encryption, is a method that uses the same key
to encrypt and decrypt the data. This means the sender and the receiver must have the same key
to decrypt the data correctly.
If the secret key is shared or lost, the security of the data is no longer guaranteed. Critical
actions for symmetric encryption methods represent the distribution, storage, and exchange of
the keys. Advanced Encryption Standard (AES) and Data Encryption Standard (DES) are
examples of symmetric encryption algorithms.
Asymmetric Encryption:
Asymmetric encryption, also known as public-key encryption, is a method of encryption that
uses two different keys:
• a public key
• a private key
The public key is used to encrypt the data, while the private key is used to decrypt the data.
This means anyone can use a public key to encrypt data for someone, but only the recipient
with the associated private key can decrypt the data.
Asymmetric encryption methods include Rivest–Shamir–Adleman (RSA), Pretty Good
Privacy (PGP), and Elliptic Curve Cryptography (ECC).
Public-Key Encryption
One advantage of asymmetric encryption is its security. Since the security is based on very
hard-to-solve mathematical problems, simple attacks cannot crack it. Furthermore, the issue of
key exchange is bypassed. This is a significant problem with symmetric encryption methods.
However, since the public key can be accessible to everyone, there is no need to exchange keys
secretly. In addition, the asymmetric methods open up the possibility of authentication with
digital signatures.
Cipher Modes
A cipher mode refers to how a block cipher algorithm encrypts a plaintext message. A block
cipher algorithm encrypts data, each using fixed-size blocks of data (usually 64 or 128 bits). A
cipher mode defines how these blocks are processed and combined to encrypt a message of any
length.
Example:
Symmetric Encryption:
There are many programs available for symmetric encryption. We will focus on two, which are
widely used for asymmetric encryption as well:
• GNU Privacy Guard
• OpenSSL Project
GNU Privacy Guard:
The GNU Privacy Guard, also known as GnuPG or GPG, implements the OpenPGP standard.
We can encrypt a file using GnuPG (GPG) using the following command:
gpg --symmetric --cipher-algo CIPHER message.txt, where CIPHER is the name of the
encryption algorithm. You can check supported ciphers using the command gpg --version. The
encrypted file will be saved as message.txt.gpg.
The default output is in the binary OpenPGP format; however, if you prefer to create an ASCII
armoured output, which can be opened in any text editor, you should add the option --armor.
For example, gpg --armor --symmetric --cipher-algo CIPHER message.txt.
You can decrypt using the following command:
gpg --output original_message.txt --decrypt message.gpg
OpenSSL Project:
The OpenSSL Project maintains the OpenSSL software.
We can encrypt a file using OpenSSL using the following command:
openssl aes-256-cbc -e -in message.txt -out encrypted_message
We can decrypt the resulting file using the following command:
openssl aes-256-cbc -d -in encrypted_message -out original_message.txt
To make the encryption more secure and resilient against brute-force attacks, we can add -
pbkdf2 to use the Password-Based Key Derivation Function 2 (PBKDF2); moreover, we can
specify the number of iterations on the password to derive the encryption key using -iter
NUMBER. To iterate 10,000 times, the previous command would become:
openssl aes-256-cbc -pbkdf2 -iter 10000 -e -in message.txt -out encrypted_message
Consequently, the decryption command becomes:
openssl aes-256-cbc -pbkdf2 -iter 10000 -d -in encrypted_message -out
original_message.txt
In the following questions, we will use gpg and openssl on the AttackBox to carry out
symmetric encryption.
The necessary files for this task are located
under /root/Rooms/cryptographyintro/task02. The zip file attached to this task can be
used to tackle the questions of tasks 2, 3, 4, 5, and 6.
Bob has received the file ciphertext_message sent to him from Alice. You can
find the key you need in the same folder. What is the first word of the original
plaintext?