Last active
October 8, 2020 11:01
-
-
Save IhorYachmenov/3de282a602b72edc930c378b7ebc26bc to your computer and use it in GitHub Desktop.
StackOverFlow Example
This file contains hidden or 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
func StackOverFrowReadPCKS12() { | |
if let url = Bundle.main.url(forResource: "client", withExtension: "p12") { | |
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<UnsafeRawPointer?>.allocate(capacity: keys.count) | |
keysPointer.initialize(to: keys) | |
let valuesPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: values.count) | |
valuesPointer.initialize(to: values) | |
var items = CFArrayCreate(kCFAllocatorDefault, UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 0), 0, nil) | |
let securityError = SecPKCS12Import(inPKCS12Data!,[ | |
kSecImportExportPassphrase: "******" | |
] as CFDictionary, &items) | |
if (securityError == 0) { | |
print("Certificate installed Successfully") | |
} else { | |
print("Certificate installation failed") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment