Objective-C Requires Chilkat v11.0.0+
Objective-C
Sign an email with a key in the Windows Current User certificate store
See more DKIM Examples
Run on Windows as the account that owns the signing certificate. Copy its thumbprint from Current User > Personal and supply it as hexadecimal digits. The thumbprint selects a certificate. The DKIM signature itself uses RSA-SHA256.
The certificate needs an accessible, exportable RSA private key for GetPrivateKey. Publish its matching public key under the selector in DNS. DKIM recipients use that DNS key to verify the message. An X.509 chain is unnecessary for this step.
Chilkat Objective-C Downloads
#import <CkoCertStore.h>
#import <CkoJsonObject.h>
#import <CkoCert.h>
#import <CkoPrivateKey.h>
#import <CkoDkim.h>
#import <CkoBinData.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoCertStore *store = [[CkoCertStore alloc] init];
success = [store OpenCurrentUserStore: YES];
if (success != YES) {
NSLog(@"%@",store.LastErrorText);
return;
}
CkoJsonObject *search = [[CkoJsonObject alloc] init];
[search UpdateString: @"thumbprint" value: @"YOUR_CERTIFICATE_THUMBPRINT"];
CkoCert *cert = [[CkoCert alloc] init];
success = [store FindCert: search cert: cert];
if (success != YES) {
NSLog(@"%@",store.LastErrorText);
return;
}
if ([cert HasPrivateKey] != YES) {
NSLog(@"%@",@"The selected certificate has no accessible private key.");
return;
}
CkoPrivateKey *privateKey = [[CkoPrivateKey alloc] init];
success = [cert GetPrivateKey: privateKey];
if (success != YES) {
NSLog(@"%@",cert.LastErrorText);
return;
}
CkoDkim *signer = [[CkoDkim alloc] init];
signer.DkimDomain = @"example.com";
signer.DkimSelector = @"mail2026";
signer.DkimAlg = @"rsa-sha256";
success = [signer SetDkimPrivateKey: privateKey];
if (success != YES) {
NSLog(@"%@",signer.LastErrorText);
return;
}
CkoBinData *message = [[CkoBinData alloc] init];
success = [message LoadFile: @"message.eml"];
if (success != YES) {
NSLog(@"%@",@"Could not read message.eml.");
return;
}
success = [signer DkimSign: message];
if (success != YES) {
NSLog(@"%@",signer.LastErrorText);
return;
}
success = [message WriteFile: @"signed.eml"];
if (success != YES) {
NSLog(@"%@",@"Could not write signed.eml.");
return;
}
NSLog(@"%@",@"Saved signed.eml.");