Here is my code :
func aesEncrypt(key: String, iv: String) throws -> String
{
let data = self.dataUsingEncoding(NSUTF8StringEncoding)
let enc = try AES(key: key, iv: iv, blockMode:.CBC).encrypt(data!.arrayOfBytes())
let encData = NSData(bytes: enc, length: Int(enc.count))
let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));
let result = String(base64String)
return result
}
func aesDecrypt(key: String, iv: String) throws -> String
{
let data = NSData(base64EncodedString: self, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
let dec = try AES(key: key, iv: iv, blockMode:.CBC).decrypt(data!.arrayOfBytes())
let decData = NSData(bytes: dec, length: Int(dec.count))
let result = NSString(data: decData, encoding: NSUTF8StringEncoding)
return String(result!)
}
The line:
data!.arrayOfBytes()
is producing the error
Ambiguous use of 'arrayOfBytes()'
. I have checked similar questions but none have helped.
The error perisist on both Xcode 7.3 Swift 2.2 and Xcode 8.0 Swift 2.3.
I commented out the PusherSwift framework in Xcdoe 7.3 and it worked.
I am not sure if it is a bug or something I have copied wrong.
If PusherSwift is pusher-websocket-swift, then it looks like they just dropped CryptoSwift directly into their module. If you're also importing CryptoSwift directly, then these will collide. This is a mistake by Pusher. They can't just drop another library into their own without taking special care that it will not collide.