Junior — Middle
What types of algorithms are used for data encryption and how are they classified?
sobes.tech AI
Answer from AI
Data encryption algorithms are divided into two main categories:
-
Symmetric algorithms — use the same key for encryption and decryption. They are fast and efficient for large volumes of data but require secure key transmission.
- Examples: AES, DES, 3DES, Blowfish.
-
Asymmetric algorithms — use a pair of keys: a public key for encryption and a private key for decryption. They allow secure key exchange but are slower.
- Examples: RSA, ECC (elliptic curves), DSA.
There are also hash functions (not encryption in the traditional sense), which create a unique fixed-size digest from data, such as SHA-256.
Classification by purpose:
- Stream ciphers — encrypt data one bit or byte at a time (e.g., RC4).
- Block ciphers — encrypt fixed-size blocks (e.g., AES with a 128-bit block).
Example of using AES in Python with the cryptography library:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import os
key = os.urandom(32) # 256-bit key
iv = os.urandom(16) # initialization vector
cipher = Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend())
encryptor = cipher.encryptor()
ciphertext = encryptor.update(b"secret data") + encryptor.finalize()