I am working on an iOS5 application that will facilitate mobile payments between two users. As part of the payment process, the sender and the recipient need to communicate with
Swift 4.0
if let url = Bundle.main.url(forResource: "XXX", withExtension: "pem") {
let PKCS12Data = NSData(contentsOf: url)
let inPKCS12Data = CFDataCreate(kCFAllocatorDefault, PKCS12Data!.bytes.assumingMemoryBound(to: UInt8.self), (PKCS12Data?.length)!)
let keys: [CFString] = [kSecImportExportPassphrase]
let values: [CFTypeRef] = []
let keysPointer = UnsafeMutablePointer.allocate(capacity: keys.count)
keysPointer.initialize(to: keys)
let valuesPointer = UnsafeMutablePointer.allocate(capacity: values.count)
valuesPointer.initialize(to: values)
let optionsDictionary = CFDictionaryCreate(kCFAllocatorDefault, keysPointer, valuesPointer, 1, nil, nil)
var items = CFArrayCreate(kCFAllocatorDefault, UnsafeMutablePointer.allocate(capacity: 0), 0, nil)
let securityError = SecPKCS12Import(inPKCS12Data!, optionsDictionary!, &items)
if (securityError == 0) {
print("Certificate installed Successfully")
} else {
print("Certificate installation failed")
}
}