swiftmacosswift4cryptoswift

CryptoSWIFT- Type of expression is ambiguous without more context


Im using cryptoswift to decrypt a string

let decrypted2 =  try AES(key: "35%6HyBW", iv: "erewf^%", blockMode: .CBC, padding: .pkcs7).decrypt(text2)

But I keep getting Type of expression is ambiguous without more context Complie time error


Solution

  • You've got two typos here.

    #1, the prototype you're using doesn't exist. Blockmode takes a CBC(iv:) argument.

    #2, you need to convert strings into a [UInt8] array.

    So use:

    let aes = try AES(key: [UInt8]("35%6HyBW".utf8), blockMode: CBC(iv: [UInt8]("erewf^%".utf8)), padding: .pkcs7)