(Objective-C) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64. Note: This example requires Chilkat v11.0.0 or greater.
#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);
|