-
-
Save MyoThuraZaw/f62e8b14b1df12aa0464d8b57b1e5154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Data { | |
var hexString: String { | |
return self.reduce("", { $0 + String(format: "%02x", $1) }) | |
} | |
} | |
do { | |
let sourceData = "AES256".data(using: .utf8)! | |
let password = "password" | |
let salt = AES256Crypter.randomSalt() | |
let iv = AES256Crypter.randomIv() | |
let key = try AES256Crypter.createKey(password: password.data(using: .utf8)!, salt: salt) | |
let aes = try AES256Crypter(key: key, iv: iv) | |
let encryptedData = try aes.encrypt(sourceData) | |
let decryptedData = try aes.decrypt(encryptedData) | |
print("Encrypted hex string: \(encryptedData.hexString)") | |
print("Decrypted hex string: \(decryptedData.hexString)") | |
} catch { | |
print("Failed") | |
print(error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment