CCA 地点:"Error!!! in decrypting application request"
CCAvenue: "Error!!! in decrypting application request"
我正在尝试将 CCAvenue 支付网关集成到我用 swift4 开发的 iOS 应用程序中。
我得到
"Error!!! Problem in decrypting application request"
我已经检查了在 给出的答案,但我的情况不顺利。
这是我从文档中尝试过的内容
private func gettingRsaKey(completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()){
let serialQueue = DispatchQueue(label: "serialQueue", qos: .userInitiated)
serialQueue.sync {
print("access_code=\(CC_AVENUE_ACCESSKEY)")
print("order_id=\(self.orderId)")
self.rsaKeyDataStr = "access_code=\(CC_AVENUE_ACCESSKEY)&order_id=\(self.orderId)"
let requestData = self.rsaKeyDataStr.data(using: String.Encoding.utf8)
guard let urlFromString = URL(string: CC_AVENUE_RSAURL) else{
return
}
var urlRequest = URLRequest(url: urlFromString)
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
urlRequest.httpMethod = "POST"
urlRequest.httpBody = requestData
let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)
session.dataTask(with: urlRequest 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")
completion(false, "Not proper data for RSA Key" as AnyObject?)
return
}
print("data :: ",data)
completion(true, data as AnyObject?)
}
else{
completion(false, "Unable to generate RSA Key please check" as AnyObject?)
}
}.resume()
}
}
var request: NSMutableURLRequest?
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)¤cy=\(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
}
DispatchQueue.main.async {
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()
}
我能够生成 RSA 密钥,但无法继续。
注*
我有真实账户,我正在使用 accesscode 和 Merchant key 作为账户
AccessCode 和 orderId 与用于生成 RSA 密钥的相同。
嘿,我遇到了同样的问题。这是因为新的 CCAvenue SDK。 CCAvenue 加载页面请求的流程分为三个步骤。
1) 我们从服务器获得了一个 RSA 密钥。
2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。
3) 在网络视图中打开请求。
当第 1 步和第 3 步之间没有延迟时,就会出现此问题。为解决此问题,新 SDK 引入了一个创建延迟的新步骤。
1) 我们从服务器获得了一个 RSA 密钥。
2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。
3) CCAvenue 在这里引入了一个新的 URLRequest 只是为了在第 1 步和第 4 步中进行延迟
4) 在网络视图中打开请求。
这在大多数情况下都有效,但当第 3 步以毫秒为单位完成时失败,或者换句话说,第 1 步和第 4 步没有延迟或延迟很少。
因此这里的解决方法是在第 1 步和第 4 步中创建一个手动延迟。
所以将您的函数更改为以下:
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)¤cy=\(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()
}
我正在尝试将 CCAvenue 支付网关集成到我用 swift4 开发的 iOS 应用程序中。 我得到
"Error!!! Problem in decrypting application request"
我已经检查了在
这是我从文档中尝试过的内容
private func gettingRsaKey(completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()){
let serialQueue = DispatchQueue(label: "serialQueue", qos: .userInitiated)
serialQueue.sync {
print("access_code=\(CC_AVENUE_ACCESSKEY)")
print("order_id=\(self.orderId)")
self.rsaKeyDataStr = "access_code=\(CC_AVENUE_ACCESSKEY)&order_id=\(self.orderId)"
let requestData = self.rsaKeyDataStr.data(using: String.Encoding.utf8)
guard let urlFromString = URL(string: CC_AVENUE_RSAURL) else{
return
}
var urlRequest = URLRequest(url: urlFromString)
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
urlRequest.httpMethod = "POST"
urlRequest.httpBody = requestData
let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)
session.dataTask(with: urlRequest 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")
completion(false, "Not proper data for RSA Key" as AnyObject?)
return
}
print("data :: ",data)
completion(true, data as AnyObject?)
}
else{
completion(false, "Unable to generate RSA Key please check" as AnyObject?)
}
}.resume()
}
}
var request: NSMutableURLRequest?
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)¤cy=\(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
}
DispatchQueue.main.async {
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()
}
我能够生成 RSA 密钥,但无法继续。
注*
我有真实账户,我正在使用 accesscode 和 Merchant key 作为账户 AccessCode 和 orderId 与用于生成 RSA 密钥的相同。
嘿,我遇到了同样的问题。这是因为新的 CCAvenue SDK。 CCAvenue 加载页面请求的流程分为三个步骤。
1) 我们从服务器获得了一个 RSA 密钥。
2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。
3) 在网络视图中打开请求。
当第 1 步和第 3 步之间没有延迟时,就会出现此问题。为解决此问题,新 SDK 引入了一个创建延迟的新步骤。
1) 我们从服务器获得了一个 RSA 密钥。
2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。
3) CCAvenue 在这里引入了一个新的 URLRequest 只是为了在第 1 步和第 4 步中进行延迟
4) 在网络视图中打开请求。
这在大多数情况下都有效,但当第 3 步以毫秒为单位完成时失败,或者换句话说,第 1 步和第 4 步没有延迟或延迟很少。
因此这里的解决方法是在第 1 步和第 4 步中创建一个手动延迟。
所以将您的函数更改为以下:
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)¤cy=\(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()
}