Sample code for 30+ languages & platforms
Objective-C

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Objective-C Downloads

Objective-C
#import <CkoCert.h>
#import <CkoPublicKey.h>
#import <CkoRsa.h>
#import <NSString.h>

BOOL success = NO;

CkoCert *cert = [[CkoCert alloc] init];

success = [cert LoadFromFile: @"qa_data/pem/mf_public_rsa.pem"];
if (success == NO) {
    NSLog(@"%@",cert.LastErrorText);
    return;
}

CkoPublicKey *pubKey = [[CkoPublicKey alloc] init];
[cert GetPublicKey: pubKey];

CkoRsa *rsa = [[CkoRsa alloc] init];
[rsa UsePublicKey: pubKey];

rsa.EncodingMode = @"base64";
NSString *encryptedStr = [rsa EncryptStringENC: @"hello" bUsePrivateKey: NO];
NSLog(@"%@%@",@"encrypted string = ",encryptedStr);