0

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.

jww
  • 97,681
  • 90
  • 411
  • 885
Darkwonder
  • 1,149
  • 1
  • 13
  • 26
  • 1
    This means there's more than one function of that name with a similar signature. You'll need to differentiate between the 2 (or more) somehow. Try finding the other version and placing it behind a namespace prefix. – Carcigenicate Oct 03 '16 at 15:11
  • 1
    It is best to avoid using CryptoSwift, among other things it is 500 to 1000 times slower than Common Crypto based implementations. Apple's Common Crypto is FIPS certified and as such has been well vetted, using CryptoSwift is taking a chance on correctness and security. If you need more security use [RNCryptor](https://github.com/RNCryptor) which is available in several languages for several platforms. It is secure, well vetted and under current development/maintenance. It provides all the details such as a random iv, message authentication, key extension and versioning for strong security. – zaph Oct 03 '16 at 15:22

1 Answers1

0

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.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • You were 100% right. I can't believe it... I didn't even want to work with that **** of framework. I had to since it is a project requirement, but I was having trouble with it since day 1, and now this. After I //import PusherSwift everything works 100%. – Darkwonder Oct 03 '16 at 15:40