Sample code for 30+ languages & platforms
Objective-C

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

Chilkat Objective-C Downloads

Objective-C
#import <CkoCert.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadFromFile: @"C:/certs_and_keys/Certificate.cer"];
if (success == NO) {
    NSLog(@"%@",cert.LastErrorText);
    return;
}

CkoStringBuilder *sbPem = [[CkoStringBuilder alloc] init];
success = [sbPem LoadFile: @"C:/certs_and_keys/PrivateKey.pem" charset: @"utf-8"];
if (success == NO) {
    NSLog(@"%@",@"Failed to load private key PEM");
    return;
}

success = [cert SetPrivateKeyPem: [sbPem GetAsString]];
if (success == NO) {
    NSLog(@"%@",cert.LastErrorText);
    return;
}

NSLog(@"%@",@"The certificate and associated private key are now loaded and ready for signing.");