How to do AES 128 encryption of a string in Swift using Xcode and send it as POST to the server?... I am new to Xcode and am learning to encrypt the string data and want to send
Based on examples from: https://github.com/krzyzanowskim/CryptoSwift
To encrypt a string using CryptoSwift:
func encrypt(text: String) -> String? {
if let aes = try? AES(key: "passwordpassword", iv: "drowssapdrowssap"),
let encrypted = try? aes.encrypt(Array(text.utf8)) {
return encrypted.toHexString()
}
return nil
}
To decrypt:
func decrypt(hexString: String) -> String? {
if let aes = try? AES(key: "passwordpassword", iv: "drowssapdrowssap"),
let decrypted = try? aes.decrypt(Array(hex: hexString)) {
return String(data: Data(bytes: decrypted), encoding: .utf8)
}
return nil
}
To send the values to server look up: HTTP Request in Swift with POST method or any one of the thousands of posts how to send data to server.