Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.6.0+

Azure Key Vault: Import a PFX Certificate with the REST API

See more Azure Key Vault Examples

Requires Chilkat 11.6.0 or later. Keep qa_data/azure/keyvault.json and token/PFX files private, outside web content and source control, with access restricted to the application identity. Use placeholders replaced by your configuration, never commit credentials. Create output directories before running file-writing examples. These examples target Azure public-cloud vaults, not Managed HSM or sovereign-cloud endpoints.

Uses HTTPS and Key Vault data-plane API 2026-04-01. Configure vault_name and first run the client-credentials token example. It writes access_token and an expires_at UTC timestamp to qa_data/tokens/azureKeyVaultToken.json. Each request checks expiration; refresh is explicit. The sample stops on errors and does not retry. Production callers should handle 429/Retry-After and transient failures with bounded backoff, and reconcile uncertain writes. Redirects are disabled.

Set cert_name and string pfx_password; load a PFX containing the leaf certificate and its private key from qa_data/pfx/myCertAndKey.pfx. The sample accepts RSA 2048/3072/4096 and NIST EC P-256/P-384/P-521. Import creates a new version if the name already exists. Keep a protected backup and reconcile uncertain failures before retrying. Requires certificates/import. Keep PFX material, request bodies, and diagnostics private; only resource identifiers are printed. The returned leaf certificate is checked against the source.

Explicitly selects a nonexportable private-key policy and disables key reuse. Existing certificate policy constraints can reject incompatible imports; choose a new name or deliberately reconcile policy. This does not delete the original local PFX. The standard base64 request contains the entire PFX, protected in transit by verified TLS; the PFX password comes from private configuration.

Microsoft reference

Chilkat Objective-C Downloads

Objective-C
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpRequest.h>
#import <CkoHttpResponse.h>
#import <CkoDateTime.h>
#import <CkoCert.h>
#import <CkoPrivateKey.h>
#import <CkoPublicKey.h>
#import <NSString.h>
#import <CkoBinData.h>

BOOL success = NO;

CkoStringBuilder *stringCompare = [[CkoStringBuilder alloc] init];
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
//  Keep this configuration private, outside public web content and source control.
CkoJsonObject *config = [[CkoJsonObject alloc] init];
config.Strict = YES;
success = [config LoadFile: @"qa_data/azure/keyvault.json"];
if (success != YES) {
    NSLog(@"%@",@"Could not load private Key Vault configuration.");
    return;
}

[stringCompare SetString: [config StringOf: @"vault_name"]];
BOOL stringMatch1 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"vault_name"] intValue] != 1) || (stringMatch1 == YES)) {
    NSLog(@"%@",@"Missing or invalid vault_name.");
    return;
}

CkoStringBuilder *validate1 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet1 = [[CkoStringBuilder alloc] init];
success = [validate1 Append: [config StringOf: @"vault_name"]];
if (success != YES) {
    NSLog(@"%@",@"Could not validate vault_name.");
    return;
}

success = [alphabet1 Append: @"abcdefghijklmnopqrstuvwxyz0123456789-"];
if (success != YES) {
    NSLog(@"%@",@"Could not initialize validation.");
    return;
}

if (([validate1.Length intValue] < 3) || ([validate1.Length intValue] > 24)) {
    NSLog(@"%@",@"Invalid vault_name length.");
    return;
}

int charIndex1 = 0;
while ((charIndex1 < [validate1.Length intValue])) {
    if ([alphabet1 Contains: [validate1 GetRange: [NSNumber numberWithInt: charIndex1] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Invalid character in vault_name.");
        return;
    }

    charIndex1 = charIndex1 + 1;
}

CkoStringBuilder *vaultName = [[CkoStringBuilder alloc] init];
[vaultName Append: [config StringOf: @"vault_name"]];
CkoStringBuilder *letters = [[CkoStringBuilder alloc] init];
[letters Append: @"abcdefghijklmnopqrstuvwxyz"];
if (([letters Contains: [vaultName GetRange: [NSNumber numberWithInt: 0] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) || ([vaultName EndsWith: @"-" caseSensitive: YES] == YES) || ([vaultName Contains: @"--" caseSensitive: YES] == YES)) {
    NSLog(@"%@",@"Invalid vault_name.");
    return;
}

CkoStringBuilder *origin = [[CkoStringBuilder alloc] init];
success = [origin Append: @"https://"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [origin Append: [config StringOf: @"vault_name"]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [origin Append: @".vault.azure.net"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.FollowRedirects = NO;
http.ConnectTimeout = [NSNumber numberWithInt:20];
http.ReadTimeout = [NSNumber numberWithInt:60];
http.VerboseLogging = NO;
CkoHttpRequest *request = [[CkoHttpRequest alloc] init];
request.HttpVerb = @"GET";
CkoHttpResponse *response = [[CkoHttpResponse alloc] init];
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
//  First run Get a Key Vault access token.
CkoJsonObject *token = [[CkoJsonObject alloc] init];
token.Strict = YES;
success = [token LoadFile: @"qa_data/tokens/azureKeyVaultToken.json"];
if (success != YES) {
    NSLog(@"%@",@"Could not read the private token file.");
    return;
}

[stringCompare SetString: [token StringOf: @"access_token"]];
BOOL stringMatch2 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[token JsonTypeOf: @"access_token"] intValue] != 1) || (stringMatch2 == YES)) {
    NSLog(@"%@",@"Missing or invalid access_token.");
    return;
}

[stringCompare SetString: [token StringOf: @"expires_at"]];
BOOL stringMatch3 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[token JsonTypeOf: @"expires_at"] intValue] != 1) || (stringMatch3 == YES)) {
    NSLog(@"%@",@"Missing or invalid expires_at.");
    return;
}

CkoDateTime *expires = [[CkoDateTime alloc] init];
CkoDateTime *now = [[CkoDateTime alloc] init];
success = [expires SetFromTimestamp: [token StringOf: @"expires_at"]];
if (success != YES) {
    NSLog(@"%@",@"Invalid token expiration.");
    return;
}

http.AuthToken = [token StringOf: @"access_token"];
[stringCompare SetString: [config StringOf: @"cert_name"]];
BOOL stringMatch4 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"cert_name"] intValue] != 1) || (stringMatch4 == YES)) {
    NSLog(@"%@",@"Missing or invalid cert_name.");
    return;
}

CkoStringBuilder *validate2 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet2 = [[CkoStringBuilder alloc] init];
success = [validate2 Append: [config StringOf: @"cert_name"]];
if (success != YES) {
    NSLog(@"%@",@"Could not validate cert_name.");
    return;
}

success = [alphabet2 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
    NSLog(@"%@",@"Could not initialize validation.");
    return;
}

if (([validate2.Length intValue] < 1) || ([validate2.Length intValue] > 127)) {
    NSLog(@"%@",@"Invalid cert_name length.");
    return;
}

int charIndex2 = 0;
while ((charIndex2 < [validate2.Length intValue])) {
    if ([alphabet2 Contains: [validate2 GetRange: [NSNumber numberWithInt: charIndex2] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Invalid character in cert_name.");
        return;
    }

    charIndex2 = charIndex2 + 1;
}

if ([[config JsonTypeOf: @"pfx_password"] intValue] != 1) {
    NSLog(@"%@",@"Missing pfx_password string; empty is allowed for an unprotected PFX.");
    return;
}

CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadPfxFile: @"qa_data/pfx/myCertAndKey.pfx" password: [config StringOf: @"pfx_password"]];
if (success != YES) {
    NSLog(@"%@",@"Could not load PFX; inspect diagnostics privately.");
    return;
}

CkoPrivateKey *privateKey = [[CkoPrivateKey alloc] init];
success = [cert GetPrivateKey: privateKey];
if (success != YES) {
    NSLog(@"%@",@"PFX must contain a usable private key.");
    return;
}

//  Inspect only the PUBLIC JWK. Never print or export a private JWK for key inspection.
CkoPublicKey *publicKey = [[CkoPublicKey alloc] init];
success = [privateKey ToPublicKey: publicKey];
if (success != YES) {
    NSLog(@"%@",@"Could not get the public key.");
    return;
}

NSString *publicJwk = [publicKey GetJwk];
if (publicKey.LastMethodSuccess != YES) {
    NSLog(@"%@",@"Could not inspect the public key.");
    return;
}

CkoJsonObject *keyInfo = [[CkoJsonObject alloc] init];
keyInfo.Strict = YES;
success = [keyInfo Load: publicJwk];
if (success != YES) {
    NSLog(@"%@",@"Invalid public JWK.");
    return;
}

BOOL supported = NO;
[stringCompare SetString: [keyInfo StringOf: @"kty"]];
BOOL stringMatch5 = [stringCompare ContentsEqual: @"RSA" caseSensitive: YES];
if (stringMatch5 == YES) {
    supported = ([privateKey.BitLength intValue] == 2048) || ([privateKey.BitLength intValue] == 3072) || ([privateKey.BitLength intValue] == 4096);
}

[stringCompare SetString: [keyInfo StringOf: @"kty"]];
BOOL stringMatch6 = [stringCompare ContentsEqual: @"EC" caseSensitive: YES];
if (stringMatch6 == YES) {
    [stringCompare SetString: [keyInfo StringOf: @"crv"]];
    BOOL stringMatch7 = [stringCompare ContentsEqual: @"P-256" caseSensitive: YES];
    [stringCompare SetString: [keyInfo StringOf: @"crv"]];
    BOOL stringMatch8 = [stringCompare ContentsEqual: @"P-384" caseSensitive: YES];
    [stringCompare SetString: [keyInfo StringOf: @"crv"]];
    BOOL stringMatch9 = [stringCompare ContentsEqual: @"P-521" caseSensitive: YES];
    if ((stringMatch7 == YES) || (stringMatch8 == YES) || (stringMatch9 == YES)) {
        supported = YES;
    }

}

if (supported != YES) {
    NSLog(@"%@",@"This example supports RSA 2048/3072/4096 and NIST P-256/P-384/P-521.");
    return;
}

CkoBinData *pfxBytes = [[CkoBinData alloc] init];
success = [pfxBytes LoadFile: @"qa_data/pfx/myCertAndKey.pfx"];
if (success != YES) {
    NSLog(@"%@",@"Could not read the PFX.");
    return;
}

CkoJsonObject *body = [[CkoJsonObject alloc] init];
success = [body UpdateString: @"value" value: [pfxBytes GetEncoded: @"base64"]];
if (success != YES) {
    NSLog(@"%@",@"Could not set value.");
    return;
}

success = [body UpdateString: @"pwd" value: [config StringOf: @"pfx_password"]];
if (success != YES) {
    NSLog(@"%@",@"Could not set pwd.");
    return;
}

success = [body UpdateString: @"policy.key_props.kty" value: [keyInfo StringOf: @"kty"]];
if (success != YES) {
    NSLog(@"%@",@"Could not set policy.key_props.kty.");
    return;
}

success = [body UpdateBool: @"policy.key_props.exportable" value: NO];
if (success != YES) {
    NSLog(@"%@",@"Could not set nonexportable policy.");
    return;
}

success = [body UpdateBool: @"policy.key_props.reuse_key" value: NO];
if (success != YES) {
    NSLog(@"%@",@"Could not set key reuse policy.");
    return;
}

success = [body UpdateString: @"policy.secret_props.contentType" value: @"application/x-pkcs12"];
if (success != YES) {
    NSLog(@"%@",@"Could not set policy.secret_props.contentType.");
    return;
}

[stringCompare SetString: [keyInfo StringOf: @"kty"]];
BOOL stringMatch10 = [stringCompare ContentsEqual: @"RSA" caseSensitive: YES];
if (stringMatch10 == YES) {
    success = [body UpdateInt: @"policy.key_props.key_size" value: privateKey.BitLength];
    if (success != YES) {
        NSLog(@"%@",@"Could not set RSA key size.");
        return;
    }

}
else {
    success = [body UpdateString: @"policy.key_props.crv" value: [keyInfo StringOf: @"crv"]];
    if (success != YES) {
        NSLog(@"%@",@"Could not set policy.key_props.crv.");
        return;
    }

}

CkoStringBuilder *importUrl = [[CkoStringBuilder alloc] init];
success = [importUrl Append: [origin GetAsString]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [importUrl Append: @"/certificates/"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [importUrl Append: [config StringOf: @"cert_name"]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [importUrl Append: @"/import?api-version=2026-04-01"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [now SetFromCurrentSystemTime];
if (success != YES) {
    NSLog(@"%@",@"Could not read current time.");
    return;
}

if ([[expires DiffSeconds: now] intValue] <= 60) {
    NSLog(@"%@",@"Token is expired or near expiration. Obtain a new token before continuing.");
    return;
}

success = [http HttpJson: @"POST" url: [importUrl GetAsString] json: body contentType: @"application/json" response: response];
if (success != YES) {
    NSLog(@"%@",@"Request failed or its outcome is uncertain. Reconcile a write before retrying.");
    return;
}

if ([response.StatusCode intValue] != 200) {
    NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
    NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
    //  Do not print full response bodies, tokens, or diagnostic logs.
    NSLog(@"%@",@"Request failed. Inspect private diagnostics; reconcile writes before retrying.");
    return;
}

success = [result Load: response.BodyStr];
if (success != YES) {
    NSLog(@"%@",@"Expected a well-formed JSON response.");
    return;
}

CkoStringBuilder *certificateBase = [[CkoStringBuilder alloc] init];
success = [certificateBase Append: [origin GetAsString]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [certificateBase Append: @"/certificates/"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [certificateBase Append: [config StringOf: @"cert_name"]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

CkoStringBuilder *bundlePrefix = [[CkoStringBuilder alloc] init];
success = [bundlePrefix Append: [certificateBase GetAsString]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [bundlePrefix Append: @"/"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

[stringCompare SetString: [result StringOf: @"id"]];
BOOL stringMatch11 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"id"] intValue] != 1) || (stringMatch11 == YES)) {
    NSLog(@"%@",@"Missing or invalid id.");
    return;
}

[stringCompare SetString: [result StringOf: @"kid"]];
BOOL stringMatch12 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"kid"] intValue] != 1) || (stringMatch12 == YES)) {
    NSLog(@"%@",@"Missing or invalid kid.");
    return;
}

[stringCompare SetString: [result StringOf: @"cer"]];
BOOL stringMatch13 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"cer"] intValue] != 1) || (stringMatch13 == YES)) {
    NSLog(@"%@",@"Missing or invalid cer.");
    return;
}

CkoStringBuilder *certificateVersionId = [[CkoStringBuilder alloc] init];
success = [certificateVersionId Append: [result StringOf: @"id"]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

if ([certificateVersionId StartsWith: [bundlePrefix GetAsString] caseSensitive: YES] != YES) {
    NSLog(@"%@",@"Returned identifier is outside the expected vault/resource.");
    return;
}

NSString *certificateVersion = [certificateVersionId GetRange: bundlePrefix.Length numChars: [NSNumber numberWithInt: ([certificateVersionId.Length intValue] - [bundlePrefix.Length intValue])] removeFlag: NO];
CkoStringBuilder *validate7 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet7 = [[CkoStringBuilder alloc] init];
success = [validate7 Append: certificateVersion];
if (success != YES) {
    NSLog(@"%@",@"Could not validate resource identifier.");
    return;
}

success = [alphabet7 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
    NSLog(@"%@",@"Could not initialize validation.");
    return;
}

if (([validate7.Length intValue] < 1) || ([validate7.Length intValue] > 127)) {
    NSLog(@"%@",@"Invalid resource identifier length.");
    return;
}

int charIndex7 = 0;
while ((charIndex7 < [validate7.Length intValue])) {
    if ([alphabet7 Contains: [validate7 GetRange: [NSNumber numberWithInt: charIndex7] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Invalid character in resource identifier.");
        return;
    }

    charIndex7 = charIndex7 + 1;
}

CkoStringBuilder *keyPrefix = [[CkoStringBuilder alloc] init];
success = [keyPrefix Append: [origin GetAsString]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [keyPrefix Append: @"/keys/"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

CkoStringBuilder *keyTailId = [[CkoStringBuilder alloc] init];
success = [keyTailId Append: [result StringOf: @"kid"]];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

if ([keyTailId StartsWith: [keyPrefix GetAsString] caseSensitive: YES] != YES) {
    NSLog(@"%@",@"Returned identifier is outside the expected vault/resource.");
    return;
}

NSString *keyTail = [keyTailId GetRange: keyPrefix.Length numChars: [NSNumber numberWithInt: ([keyTailId.Length intValue] - [keyPrefix.Length intValue])] removeFlag: NO];
CkoStringBuilder *keyTailParts = [[CkoStringBuilder alloc] init];
success = [keyTailParts Append: keyTail];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

NSString *keyTailName = [keyTailParts GetBefore: @"/" removeFlag: NO];
NSString *keyTailVersion = [keyTailParts GetAfterFinal: @"/" removeFlag: NO];
CkoStringBuilder *validate8 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet8 = [[CkoStringBuilder alloc] init];
success = [validate8 Append: keyTailName];
if (success != YES) {
    NSLog(@"%@",@"Could not validate resource name.");
    return;
}

success = [alphabet8 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
    NSLog(@"%@",@"Could not initialize validation.");
    return;
}

if (([validate8.Length intValue] < 1) || ([validate8.Length intValue] > 127)) {
    NSLog(@"%@",@"Invalid resource name length.");
    return;
}

int charIndex8 = 0;
while ((charIndex8 < [validate8.Length intValue])) {
    if ([alphabet8 Contains: [validate8 GetRange: [NSNumber numberWithInt: charIndex8] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Invalid character in resource name.");
        return;
    }

    charIndex8 = charIndex8 + 1;
}

CkoStringBuilder *validate9 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet9 = [[CkoStringBuilder alloc] init];
success = [validate9 Append: keyTailVersion];
if (success != YES) {
    NSLog(@"%@",@"Could not validate resource version.");
    return;
}

success = [alphabet9 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
    NSLog(@"%@",@"Could not initialize validation.");
    return;
}

if (([validate9.Length intValue] < 1) || ([validate9.Length intValue] > 127)) {
    NSLog(@"%@",@"Invalid resource version length.");
    return;
}

int charIndex9 = 0;
while ((charIndex9 < [validate9.Length intValue])) {
    if ([alphabet9 Contains: [validate9 GetRange: [NSNumber numberWithInt: charIndex9] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Invalid character in resource version.");
        return;
    }

    charIndex9 = charIndex9 + 1;
}

CkoStringBuilder *keyTailCanonical = [[CkoStringBuilder alloc] init];
success = [keyTailCanonical Append: keyTailName];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [keyTailCanonical Append: @"/"];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

success = [keyTailCanonical Append: keyTailVersion];
if (success != YES) {
    NSLog(@"%@",@"Could not construct URL or identifier.");
    return;
}

[stringCompare SetString: keyTail];
BOOL stringMatch14 = [stringCompare ContentsEqual: [keyTailCanonical GetAsString] caseSensitive: YES];
if (stringMatch14 != YES) {
    NSLog(@"%@",@"Expected a versioned resource identifier.");
    return;
}

NSString *certificateId = [result StringOf: @"id"];
NSString *keyId = [result StringOf: @"kid"];
CkoCert *remoteCert = [[CkoCert alloc] init];
success = [remoteCert LoadFromBase64: [result StringOf: @"cer"]];
if (success != YES) {
    NSLog(@"%@",@"Could not load the returned public certificate.");
    return;
}

NSString *sourceDer = [cert GetEncoded];
if (cert.LastMethodSuccess != YES) {
    NSLog(@"%@",@"Could not encode source certificate.");
    return;
}

NSString *importedDer = [remoteCert GetEncoded];
if (remoteCert.LastMethodSuccess != YES) {
    NSLog(@"%@",@"Could not encode imported certificate.");
    return;
}

[stringCompare SetString: sourceDer];
BOOL stringMatch15 = [stringCompare ContentsEqual: importedDer caseSensitive: YES];
if (stringMatch15 != YES) {
    NSLog(@"%@",@"Imported certificate does not match the PFX leaf certificate.");
    return;
}

NSLog(@"%@%@",@"Imported certificate ID: ",certificateId);
NSLog(@"%@%@",@"Backing key ID: ",keyId);