Objective-C
Objective-C
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat Objective-C Downloads
#import <CkoMime.h>
#import <CkoCrypt2.h>
#import <NSString.h>
BOOL success = NO;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoMime *mime = [[CkoMime alloc] init];
success = [mime LoadMimeFile: @"c:/aaworkarea/EmailInBytes.txt"];
if (success != YES) {
NSLog(@"%@",mime.LastErrorText);
return;
}
success = [mime SaveBody: @"c:/aaworkarea/smime.p7m"];
if (success != YES) {
NSLog(@"%@",mime.LastErrorText);
return;
}
CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init];
success = [crypt AddPfxSourceFile: @"c:/aaworkarea/my.pfx" password: @"pfxPassword"];
if (success == NO) {
NSLog(@"%@",crypt.LastErrorText);
return;
}
// Indicate the public-key (PKCS7) encryption/decryption should be used:
crypt.CryptAlgorithm = @"pki";
NSString *inPath = @"c:/aaworkarea/smime.p7m";
NSString *outPath = @"c:/aaworkarea/decrypted.dat";
success = [crypt CkDecryptFile: inPath destFile: outPath];
if (success == NO) {
NSLog(@"%@",crypt.LastErrorText);
return;
}
NSLog(@"%@",@"Success.");