Sample code for 30+ languages & platforms
Objective-C

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat Objective-C Downloads

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

BOOL success = NO;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoPublicKey *pubkey = [[CkoPublicKey alloc] init];

success = [pubkey LoadBase64: @"MIICdgIBADA ... A9PXLk+j5A=="];
if (success == NO) {
    NSLog(@"%@",pubkey.LastErrorText);
    return;
}

CkoRsa *rsa = [[CkoRsa alloc] init];

success = [rsa UsePublicKey: pubkey];
if (success == NO) {
    NSLog(@"%@",rsa.LastErrorText);
    return;
}

rsa.EncodingMode = @"base64";

NSString *encryptedStr = [rsa EncryptStringENC: @"12345678" bUsePrivateKey: NO];

NSLog(@"%@",encryptedStr);