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
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"
}
}
I've checked out
CryptoSwift
's documentation, and I found a sample code:and I think it uses
.pkcs7
, instead ofPKCS7()
.