I have Installed CryptoSwift framework by Pods. I am getting Encrypted data from server response. I am trying to do decrypt the data by using that below function:
func aesDecrypt(key: String, iv: String) throws -> String {
let data = Data(base64Encoded: self)!
let decrypted = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).decrypt([UInt8](data))
let decryptedData = Data(decrypted)
return String(bytes: decryptedData.bytes, encoding: .utf8) ?? "Could not decrypt"
}
I have my model class in that I am getting response using Alamofire.
func getAllShops(data : [String : AnyObject]) {
AFWrapper.requestPOSTURL(url, params: data, headers: nil, success: {(json) in
print(json)
let key = "My_Key" // length == 32
let iv = "My_iv" // length == 16
let encryptedData = json["encrypted"].string!
let enc = try! s.aesDecrypt(key: key, iv: iv)
}, failure: {(Error) in
print(Error.localizedDescription)
})
}
How can I decrypt it and can get actual data? That function is not giving me the actual data. Is there any other way to decrypt the data?