0

I have a encrypted JSON file and I am trying to decrypt it. I am using CryptoSwift framework and AES decryption. I have my key and iv for that and I have to do "AES-128-CBC" decryption.

Below is my code:

fileprivate func checkJSONDecryption() {
    if let path = Bundle.main.path(forResource: "Questions", ofType: "json") {
        print("Inside")
        do {
            let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
            let dec = try AES(key: "Key", iv: "IV").decrypt(data.bytes, padding: .zeroPadding)
            let decData = NSData(bytes: dec, length: Int(dec.count))
            let result = NSString(data: decData as Data, encoding: String.Encoding.utf8.rawValue)
            //return
            print(String(result ?? "No Data"))


        } catch {
            // handle error
        }
    }
}

After 'dec' code is not executing. How can I decrypt that JSON file data or I am missing something?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kishor Pahalwani
  • 1,010
  • 1
  • 23
  • 53
  • Since the code after 'dec' is never executed, the 'dec' line must be throwing an exception. Try catching the error to see what goes wrong. – John Snow Mar 09 '18 at 14:31
  • The operation couldn’t be completed. (CryptoSwift.AES.Error error 0.) I don't know error 0. thanks – Kishor Pahalwani Mar 09 '18 at 14:46

0 Answers0