Sobes.tech
Junior — Middle

Explain how symmetric data encryption works and its main features.

sobes.tech AI

Answer from AI

Symmetric encryption is a method where the same secret key is used for both encryption and decryption of data.

Main features:

  • One key for both encryption and decryption. The key must be known to both sender and receiver.
  • High speed. Symmetric algorithms are usually faster than asymmetric ones.
  • Key distribution problem. Securely transmitting the key between parties is a major challenge.

Examples of algorithms: AES, DES, Blowfish.

Example of usage in Python with the cryptography library:

from cryptography.fernet import Fernet

key = Fernet.generate_key()
cipher = Fernet(key)

message = b"secret message"
encrypted = cipher.encrypt(message)
decrypted = cipher.decrypt(encrypted)

print(encrypted)
print(decrypted)

Here, key is a shared secret key that must be known to both parties.