3

I am integrating the CryptoSwift and found this error "Member 'CBC' takes no arguments".

I am calling the function like this

let enc = try! AES(key: key, blockMode: .CBC(iv: iv)).encrypt(self.arrayOfBytes())
jww
  • 97,681
  • 90
  • 411
  • 885
RussVirtuoso
  • 900
  • 1
  • 9
  • 20
  • Could you show us how the variables are initialized and which version of Swift and CryptoSwift you are using? – Maarten Bodewes Dec 12 '17 at 09:57
  • Im using Swift 3.2 and CryptoSwift 0.7.0 – RussVirtuoso Dec 12 '17 at 10:09
  • It is best to avoid using CryptoSwift, amoung 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 such as timing and power attacks. – zaph Feb 07 '18 at 04:15

3 Answers3

4

Sorry I'm a little late, but just encountered this issue after running pod update. I was doing the same as you and my project broke after the update, since the new API introduces changes that are not backward compatible. To answer your question, now CBC is not a member of the BlockMode enum, so the correct way to write equivalent code with the new API is:

let enc = try! AES(key: key, blockMode: CBC(iv: iv)).encrypt(self.arrayOfBytes())

Mario Muniz
  • 61
  • 1
  • 4
0

If you're looking at the CryptoSwift API for version 3 you get the following initializer for AES:

public init(key: Array<UInt8>, iv: Array<UInt8>? = nil, blockMode: BlockMode = .CBC, padding: Padding = PKCS7()) throws {

As you can see the iv here is not a parameter of CBC - as it should be - but of the block cipher itself. You should either upgrade to Swift 4 or you should adhere to the older API.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
0

For the Swift 3.2 you should check the correct README for the API usage, as the API changed over the time.

Here is the README for Swift 3.2 (swift32 branch): https://github.com/krzyzanowskim/CryptoSwift/tree/swift32#aes-advanced-usage

To answer the question, this is the proper form for your needs:

try AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
Marcin
  • 3,694
  • 5
  • 32
  • 52