Skip to content

Instantly share code, notes, and snippets.

@jdanthinne
jdanthinne / PemToP12.swift
Last active July 27, 2023 21:31
Convert PEM certificate to P12 (PKCS#12)
import Foundation
import OpenSSL
static func pkcs12(fromPem pemCertificate: String,
withPrivateKey pemPrivateKey: String,
p12Password: String = "",
certificateAuthorityFileURL: URL? = nil) throws -> NSData {
// Create sec certificates from PEM string
let modifiedCert = pemCertificate
.replacingOccurrences(of: "-----BEGIN CERTIFICATE-----", with: "")