Objective-C
Objective-C
CAdES BES Detached Signature
See more Encryption Examples
Demonstrates how to create a CAdES BES detached signature file (.p7s).Chilkat Objective-C Downloads
#import <CkoCrypt2.h>
#import <NSString.h>
#import <CkoCert.h>
BOOL success = NO;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init];
// Use a digital certificate and private key from a PFX file (.pfx or .p12).
NSString *pfxPath = @"/Users/chilkat/testData/pfx/acme.pfx";
NSString *pfxPassword = @"test123";
CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadPfxFile: pfxPath password: pfxPassword];
if (success != YES) {
NSLog(@"%@",cert.LastErrorText);
return;
}
// Tell the crypt component to use this cert.
success = [crypt SetSigningCert: cert];
if (success != YES) {
NSLog(@"%@",crypt.LastErrorText);
return;
}
// The CadesEnabled property applies to all methods that create PKCS7 signatures.
// To create a CAdES-BES signature, set this property equal to true.
crypt.CadesEnabled = YES;
// We can sign any type of file, creating a .p7s as output:
NSString *inFile = @"/Users/chilkat/testData/pdf/sample.pdf";
NSString *sigFile = @"/Users/chilkat/testData/p7s/sample.p7s";
// Create the detached CAdES-BES signature:
success = [crypt CreateP7S: inFile p7sPath: sigFile];
if (success == NO) {
NSLog(@"%@",crypt.LastErrorText);
return;
}
success = [crypt VerifyP7S: inFile p7sFilename: sigFile];
if (success == NO) {
NSLog(@"%@",crypt.LastErrorText);
return;
}
NSLog(@"%@",@"Success!");