2

I am using Xcode 9.0 and CryptoSwift (0.7.2). I am trying to extend String to decrypt an AES128 encrypted string. I've added CryptoSwift successfully with Pods but I get the following compilation error - what am I doing wrong?

'PKCS7' cannot be constructed because it has no accessible initializers

enter image description here

Here is the extension:

import Foundation import CryptoSwift extension String { // https://stackoverflow.com/questions/27072021/aes-encrypt-and-decrypt 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" } } 
1

1 Answer 1

7

I've checked out CryptoSwift's documentation, and I found a sample code:

let decrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).decrypt(encrypted) 

and I think it uses .pkcs7, instead of PKCS7().

Sign up to request clarification or add additional context in comments.

2 Comments

Use of unresolved identifier 'encrypted' and Type 'Padding' has no member 'pkcs7
I have "let enc = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).encrypt(data!.bytes)" and now getting error "Expression type 'AES' is ambiguous without more context"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.