Created
November 2, 2019 21:25
-
-
Save OlexandrStepanov/a012c939a098b8761675f256f4f18c29 to your computer and use it in GitHub Desktop.
SecCertificate and SecKey from DER certificate in base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let crtBase64 = "..." | |
if let certificateData = Data(base64Encoded: crtBase64, options: []), | |
let certificate = SecCertificateCreateWithData(nil, certificateData as CFData) { | |
// use certificate to initialize PinnedCertificatesTrustEvaluator, or ... | |
var trust: SecTrust? | |
let policy = SecPolicyCreateBasicX509() | |
let status = SecTrustCreateWithCertificates(certificate, policy, &trust) | |
if status == errSecSuccess, let trust = trust, | |
let publicKey = SecTrustCopyPublicKey(trust) { | |
// ... use publicKey to initialize PublicKeysTrustEvaluator | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment