Skip to content

Instantly share code, notes, and snippets.

@OlexandrStepanov
Created November 2, 2019 21:25
Show Gist options
  • Save OlexandrStepanov/a012c939a098b8761675f256f4f18c29 to your computer and use it in GitHub Desktop.
Save OlexandrStepanov/a012c939a098b8761675f256f4f18c29 to your computer and use it in GitHub Desktop.
SecCertificate and SecKey from DER certificate in base64
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