Junior — Middle
Can you explain what is meant by symmetric data encryption?
sobes.tech AI
Answer from AI
Symmetric encryption is a method of data encryption where the same key is used for both encryption and decryption. This means that the sender and receiver must agree on a secret key in advance and keep it secure.
Main features:
- Fast encryption and decryption.
- A secure channel is required for key exchange.
Example algorithms: AES, DES.
Example in Python using the cryptography library:
from cryptography.fernet import Fernet
# Generate a key
key = Fernet.generate_key()
cipher = Fernet(key)
# Encryption
text = b"Hello, world!"
cipher_text = cipher.encrypt(text)
# Decryption
plain_text = cipher.decrypt(cipher_text)
print(plain_text.decode()) # Outputs: Hello, world!
Here, key is used for both encryption and decryption.