(Objective-C) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.
#import <CkoCert.h>
#import <CkoPublicKey.h>
#import <CkoRsa.h>
#import <NSString.h>
CkoCert *cert = [[CkoCert alloc] init];
BOOL success = [cert LoadFromFile: @"qa_data/pem/mf_public_rsa.pem"];
if (success == NO) {
NSLog(@"%@",cert.LastErrorText);
return;
}
CkoPublicKey *pubKey = [cert ExportPublicKey];
if (cert.LastMethodSuccess != YES) {
NSLog(@"%@",cert.LastErrorText);
return;
}
CkoRsa *rsa = [[CkoRsa alloc] init];
success = [rsa ImportPublicKeyObj: pubKey];
if (success == NO) {
NSLog(@"%@",rsa.LastErrorText);
return;
}
rsa.EncodingMode = @"base64";
NSString *encryptedStr = [rsa EncryptStringENC: @"hello" bUsePrivateKey: NO];
NSLog(@"%@%@",@"encrypted string = ",encryptedStr);
|