Я не знаю про DER или PEM .. но для p12 вы можете сделать:
private func loadCertificate(name: String, password: String?) throws -> (identity: SecIdentity, certificate: SecCertificate) {
let path = Bundle.main.path(forResource: name, ofType: "p12")!
let data = NSData(contentsOfFile: path)!
let certificate = SecCertificateCreateWithData(nil, data)!
let options = [String(kSecImportExportPassphrase):password ?? ""]
var items: CFArray? = nil
let result = SecPKCS12Import(data, options as CFDictionary, &items)
if (result != errSecSuccess) {
throw RuntimeError("Cannot Import Certificte")
}
let info = (items! as NSArray).firstObject! as! NSDictionary
let identity = info[String(kSecImportItemIdentity)] as! SecIdentity
return (identity, certificate)
}
Тогда:
let info = try loadCertificate(name: "MyCertificate", password: "Password..")
let credentials = URLCredential(identity: info.identity, certificates: [info.certificate], persistence: .forSession)