123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // TestCommon.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/6/1.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class TestCommon: NSObject {
- // MARK: 身份证识别
- ///上传图片到海科识别
- func uploadHaiKe() {
- let testKey: [UInt8] = [UInt8](CommonBase64Tools.base64DecodingToData(encodedString: "mjVyGyIPWPClJJnuHtdIiA=="))
- var test: [Int8] = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
- let key = "abcdefghabcde05h"
- let dic = NSMutableDictionary()
- dic.setValue("12312312323", forKey: "mercNo")
- let dicPara = NSMutableDictionary()
- dicPara.setValue(dic, forKey: "data")
- let jsonStr = CommonJSON.dicToJson(dic: dicPara).replacingOccurrences(of: "\n", with: "")
- let tools = CryptorTools()
- tools.loadPublicKey(withFilePath: Bundle.main.path(forResource: "uen", ofType: "cer")!)
- let keyNew = RSAEncryptor.encryptData(NSKeyedArchiver.archivedData(withRootObject: test), publicKeyWithContentsOfFile: Bundle.main.path(forResource: "uen", ofType: "cer")!)
- //let keyNew = RSAEncryptor.encryptString(key, publicKeyWithContentsOfFile: Bundle.main.path(forResource: "uen", ofType: "cer")!)
- ///Data 方式
- var signKey = tools.rsaEncryptStringData(key) //keyNew!.data(using: .utf8)! //
- let dataContent1 = jsonStr.data(using: .utf8)! as NSData
- let dataContent = dataContent1.aes128EncryptedData(withKey: "", iv: "mjVyGyIPWPClJJnuHtdIiA==")!
- // dataContent.aes
- //let dataContent2 = CryptorTools.aesEncryptString(jsonStr, keyData: signKey, iv: CommonBase64Tools.base64DecodingToData(encodedString: "mjVyGyIPWPClJJnuHtdIiA=="))
- // signKey.append(dataContent)
- let base = signKey.base64EncodedData()
- var re = URLRequest(url: URL(string: "http://hkrt.uenpay.com/api/uhf/mercManage/getMerchantInfo")!)
- re.httpMethod = "POST"
- re.setValue("utf-8", forHTTPHeaderField: "Accept-Charset")
- re.setValue("application/x-json", forHTTPHeaderField: "Content-Type")
- re.setValue("\(base.count)", forHTTPHeaderField: "Content-Length")
- re.httpBody = base
- let manage = AFURLSessionManager()
- manage.responseSerializer = AFHTTPResponseSerializer()
- manage.uploadTask(with: re, from: base, progress: { (_) in
- //print(progress);
- }) {[weak self] (_, any, error) in
- if error != nil {
- print(error)
- } else {
- print("=====")
- if any != nil {
- let data = any as! Data
- let re = self!.getResultString(str: String(data: data, encoding: .utf8)!)
- print(re)
- }
- }
- }.resume()
- }
- func getResultString(str: String) -> String {
- let tools = CryptorTools()
- tools.loadPublicKey(withFilePath: Bundle.main.path(forResource: "uen", ofType: "cer")!)
- let bstr11 = CommonBase64Tools.base64DecodingToData(encodedString: str) //base64Decoding(encodedString: str);
- let data1 = bstr11.subdata(in: Range(NSRange(location: 0, length: 256))!)
- let data2 = bstr11.subdata(in: Range(NSRange(location: 256, length: bstr11.count - 256))!)
- let key = tools.rsaDecryptData(data1)
- let keyData = key.subdata(in: Range(NSRange(location: key.count - 16, length: 16))!)
- let data = CryptorTools.aesDecryptData(data2, keyData: keyData, iv: CommonBase64Tools.base64DecodingToData(encodedString: "mjVyGyIPWPClJJnuHtdIiA=="))
- let result = String(data: data, encoding: .utf8)!
- return result
- }
- }
|