Encryption and Decryption

PB
SystemDesign.us Blog
4 min readNov 27, 2022

Visit systemdesign.us for System Design Interview Questions tagged by companies and their Solutions. Follow us on YouTube, LinkedIn, Twitter, Medium.

There are two main processes to protect the data from being accessed by unauthorized users. Encryption is the process of converting plain text into ciphertext, which is unreadable by anyone except those who have the key to decrypt it. Decryption is the reverse process of encryption, which converts ciphertext back into readable plain text.

https://www.okta.com/identity-101/password-encryption/

Symmetric-key cryptography also known as private-key cryptography, is a cryptographic technique that uses the same key to encrypt and decrypt data.

Types symmetric-key cryptography

There are two types of symmetric-key cryptography, block cipher and stream cipher.

A block cipher is a method of encrypting data in which a cryptographic key is used to encrypt and decrypt blocks of data, usually 64 bits in length.

A stream cipher is a method of encrypting data in which a cryptographic key is used to encrypt and decrypt a stream of data, one bit at a time.

Asymmetric-key cryptography, also known as public-key cryptography, is a cryptographic technique that uses two different keys: one to encrypt data and one to decrypt it. The encryption key is made public, while the decryption key is kept secret.

Types of Asymmetric-key cryptography

There are two types of asymmetric-key cryptography, digital signature and public key encryption.

Digital signature is a technique used to verify the authenticity of digital data. A digital signature is created by encrypting data with a private key, which can then be decrypted with the public key.

Public key encryption is a technique used to encrypt data with a public key, which can then be decrypted with the private key. This type of encryption is often used in e-commerce and online banking.

Advanced Encryption Standard (AES)

There are many different types of encryption algorithms, but the most common one used in symmetric-key cryptography is the Advanced Encryption Standard (AES). AES uses a 128-bit block size and supports keys of 128, 192, and 256 bits.

To encrypt data with AES, a secret key (also called a “symmetric key”) is used. This key is combined with the data using an encryption algorithm, and the result is ciphertext. The ciphertext can only be decrypted with the same key that was used to encrypt it.

AES is a block cipher, which means that it encrypts data in blocks rather than in a single stream. The size of each block is 128 bits. AES also uses what is known as a key schedule, which determines how the key will be used throughout the encryption process.

The AES algorithm is extremely secure and has been tested by cryptographers around the world. It is also fast and efficient, making it well-suited for use in devices such as wireless routers and secure communications equipment.

There are a few different modes that AES can operate in, each with its own advantages and disadvantages. The most common mode is the Electronic Codebook (ECB) mode, which encrypts each block of data independently. However, this mode is not recommended for use in most situations because it is vulnerable to certain types of attacks.

Another mode, known as Cipher Block Chaining (CBC), encrypts each block of data by combining it with the previous block of ciphertext. This makes CBC more secure than ECB, but it also makes it more complicated to implement.

AES also has a Galois/Counter Mode (GCM), which is a stream cipher mode that provides both confidentiality and integrity protection. GCM is recommended for use in situations where data needs to be both encrypted and authenticated.

The main advantage of AES is that it is very secure. The key schedule makes it resistant to known-key attacks, and the different modes of operation offer different levels of security. AES is also fast and efficient, making it well-suited for use in a variety of devices and applications.

The main disadvantage of AES is that it is a block cipher, which means that it can only encrypt data in blocks. This can be a problem when trying to encrypt large amounts of data, such as video or audio files.

Another disadvantage of AES is that it is a symmetric-key algorithm, which means that the same key must be used for both encryption and decryption. This can be a problem if the key is lost or stolen, because anyone who has the key can decrypt the data.

AES is a very secure encryption algorithm, but it has some limitations. It is best suited for use in applications where data needs to be both encrypted and authenticated.

Visit systemdesign.us for System Design Interview Questions tagged by companies and their Solutions. Follow us on YouTube, LinkedIn, Twitter, Medium.

--

--