(Objective-C) ZATCA Load Certificate and Private Key from PEM Files
Demonstrates how to load a certificate and private key from a pair of PEM files.
#import <CkoCert.h>
#import <CkoPrivateKey.h>
// The LoadFromFile method will automatically detect the file format..
CkoCert *cert = [[CkoCert alloc] init];
BOOL success = [cert LoadFromFile: @"qa_data/zatca/cert.pem"];
if (success != YES) {
NSLog(@"%@",cert.LastErrorText);
return;
}
NSLog(@"%@",cert.SubjectCN);
// Load the private key.
CkoPrivateKey *privKey = [[CkoPrivateKey alloc] init];
success = [privKey LoadPemFile: @"qa_data/zatca/ec-secp256k1-priv-key.pem"];
if (success != YES) {
NSLog(@"%@",privKey.LastErrorText);
return;
}
NSLog(@"%@%@",@"Key Type: ",privKey.KeyType);
// Associate the private key with the certificate.
success = [cert SetPrivateKey: privKey];
if (success != YES) {
NSLog(@"%@",cert.LastErrorText);
return;
}
NSLog(@"%@",@"Success.");
|