Problem in decrypting application request in CCAvenue iOS

727 Views Asked by At

I am trying to implement CCAvenue payment gateway into my app. I am following CCAvenue: “Error!!! in decrypting application request” this answer, but getting following error :

enter image description here

I have tried this code :

private func encyptCardDetails(data: Data){

guard let rsaKeytemp = String(bytes: data, encoding: String.Encoding.ascii) else{
    print("No value for rsaKeyTemp")
    return
}
rsaKey = rsaKeytemp
rsaKey = self.rsaKey.trimmingCharacters(in: CharacterSet.newlines)
rsaKey =  "-----BEGIN PUBLIC KEY-----\n\(self.rsaKey)\n-----END PUBLIC KEY-----\n"
print("rsaKey :: ",rsaKey)

let myRequestString = "amount=\(amount)&currency=\(getCurrency())"
let ccTool = CCTool()
var encVal = ccTool.encryptRSA(myRequestString, key: rsaKey)

encVal = CFURLCreateStringByAddingPercentEscapes(
    nil,
    encVal! as CFString,
    nil,
    "!*'();:@&=+$,/?%#[]" as CFString,
    CFStringBuiltInEncodings.UTF8.rawValue) as String?

let urlAsString = "https://secure.ccavenue.com/transaction/initTrans"
let encryptedStr = String(format:"merchant_id=%@&order_id=%@&redirect_url=%@&cancel_url=%@&enc_val=%@&access_code=%@", CC_AVENUE_MERCHANTID, self.orderId, CC_AVENUE_REDIRECTURL, CC_AVENUE_REDIRECTURL, encVal!,CC_AVENUE_ACCESSKEY)
print("access_code=\(CC_AVENUE_ACCESSKEY)")
print("order_id=\(self.orderId)")

let myRequestData = encryptedStr.data(using: String.Encoding.utf8)

request  = NSMutableURLRequest(url: URL(string: urlAsString)! as URL, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 30)
request?.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request?.setValue(urlAsString, forHTTPHeaderField: "Referer")
request?.httpMethod = "POST"
request?.httpBody = myRequestData

print("\n\n\nwebview :: ",request?.url as Any)
print("\n\n\nwebview :: ",request?.description as Any)
print("\n\n\nwebview :: ",request?.httpBody?.description as Any)
print("\n\n\nwebview :: ",request?.allHTTPHeaderFields! as Any)

let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)

session.dataTask(with: request! as URLRequest) {
    (data, response, error) -> Void in

    if let response = response as? HTTPURLResponse, 200...299 ~= response.statusCode{

        guard let data = data else{
            print("No value for data")
            return
        }

        // Create the delay here
        DispatchQueue.main.asyncAfter(deadline: .now()+1.0, execute: {
            self.viewWeb.loadRequest(self.request! as URLRequest)
        }
        print("data :: ",data)
    }else{
        print("into else")
        showAlertWithTitleWithMessage(message: "Unable to load webpage currently, Please try again later.")
    }
    }.resume()
}

Any help would be appreciated.

0

There are 0 best solutions below