Sobes.tech
Junior — Middle

Can you explain what data encryption means?

sobes.tech AI

Answer from AI

Data encryption is the process of converting information into a format that cannot be read without a special key or password. This is done to protect data from unauthorized access. For example, when you send a message through a messenger, it is encrypted so that no one except the recipient can read it.

An example of simple encryption in Swift using AES:

import CryptoKit

let key = SymmetricKey(size: .bits256)
let message = "Hello, world!".data(using: .utf8)!

let sealedBox = try! AES.GCM.seal(message, using: key)
let encryptedData = sealedBox.combined!

// For decryption:
let box = try! AES.GCM.SealedBox(combined: encryptedData)
let decryptedData = try! AES.GCM.open(box, using: key)
let decryptedMessage = String(data: decryptedData, encoding: .utf8)!
print(decryptedMessage) // "Hello, world!"