import CryptoKit
// Example of hashing using SHA256
let inputData = "Hello, World!"
let inputDataBytes = Data(inputData.utf8)
let hashed = SHA256.hash(data: inputDataBytes)
// Converting the hashed data to its hexadecimal representation
let hashedString = hashed.map { String(format: "%02hhx", $0) }.joined()
print("SHA256 Hash: \(hashedString)")
// Example of encryption using Symmetric Key
let key = SymmetricKey(size: .bits256)
let plaintext = "This is a secret message."
let plaintextData = Data(plaintext.utf8)
// Encrypting the plaintext
let sealedBox = try AES.GCM.seal(plaintextData, using: key)
// Decrypting the ciphertext
let decryptedData = try AES.GCM.open(sealedBox, using: key)
let decryptedMessage = String(data: decryptedData, encoding: .utf8)
print("Decrypted message: \(decryptedMessage ?? "Failed to decrypt")")
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?