Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

Sign an EML using RSA-PSS and SHA-256

See more Email Object Examples

Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.

Chilkat Objective-C Downloads

Objective-C
#import <CkoEmail.h>
#import <CkoCert.h>
#import <CkoMailMan.h>
#import <CkoBinData.h>

BOOL success = NO;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

CkoEmail *email = [[CkoEmail alloc] init];
success = [email LoadEml: @"message.eml"];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

CkoCert *cert = [[CkoCert alloc] init];
success = [cert LoadPfxFile: @"signer.pfx" password: @"PFX_PASSWORD"];
if (success != YES) {
    NSLog(@"%@",cert.LastErrorText);
    return;
}

success = [email SetSigningCert: cert];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

email.SigningAlg = @"pss";
email.SigningHashAlg = @"sha256";
email.SendSigned = YES;
CkoMailMan *mail = [[CkoMailMan alloc] init];
mail.OpaqueSigning = NO;
CkoBinData *rendered = [[CkoBinData alloc] init];
success = [mail RenderToMimeBd: email renderedMime: rendered];
if (success != YES) {
    NSLog(@"%@",mail.LastErrorText);
    return;
}

success = [rendered WriteFile: @"signed.eml"];
if (success != YES) {
    NSLog(@"%@",@"Failed: rendered.WriteFile.");
    return;
}

NSLog(@"%@",@"Saved signed.eml.");