Dkim C++ Reference Documentation
CkDkim
Current Version: 11.5.0
Chilkat.Dkim
Add DKIM signatures to MIME messages using a private key, selector,
signing domain, canonicalization settings, and selected headers.
Create or verify legacy DomainKey signatures when older mail systems or
compatibility requirements depend on them.
Verify one or more signatures in a MIME message and determine whether the
signed content, headers, and public key match.
Configure body and header canonicalization so signing and verification
match the requirements of the sending domain and receiving systems.
Retrieve DKIM public keys from DNS, prefetch keys when useful, and cache
public keys to reduce repeated DNS lookups.
Use
For an extended overview, see
Dkim Class Overview.
Sign and verify MIME email with DKIM and DomainKey signatures.
Chilkat.Dkim is the Chilkat class for applying and verifying
DKIM and DomainKey signatures on MIME email data. It supports DKIM signing
with rsa-sha256 or rsa-sha1, DomainKey signing with
rsa-sha1, configurable canonicalization, selectable signed
headers, signature counting, DNS public-key lookup, public-key caching,
public-key prefetching, and detailed verification reporting through
VerifyInfo.
DKIM signing
DomainKey support
Signature verification
Canonicalization control
DNS public keys
Verification diagnostics
VerifyInfo and related status information to understand
which signatures were found, which were checked, and why verification
succeeded or failed.
Dkim, allow the class
to locate the signature and public key, and inspect VerifyInfo
for detailed results.
Object Creation
// Local variable on the stack CkDkim obj; // Dynamically allocate/delete CkDkim *pObj = new CkDkim(); // ... delete pObj;
Properties
AbortCurrent
void put_AbortCurrent(bool newVal);
Set to true to request cancellation of a currently running operation. A synchronous operation can be cancelled from another thread by setting this property on the same object. Methods that complete quickly or do not periodically check for cancellation may finish before the request is observed.
DebugLogFilePath
const char *debugLogFilePath(void);
void put_DebugLogFilePath(const char *newVal);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
DkimAlg
Specifies the algorithm written to the a= tag of a newly created DKIM-Signature header. The default is rsa-sha256.
| Value | Meaning |
|---|---|
rsa-sha256 | RSA signing with a SHA-256 message digest. This is the recommended choice. |
rsa-sha1 | Legacy RSA signing with SHA-1. Use only when compatibility with an older system requires it. |
DkimBodyLengthCount
void put_DkimBodyLengthCount(int newVal);
Specifies the optional DKIM body-length value written to the l= tag. The value is the maximum number of bytes from the canonicalized message body to include in the body hash. The default is 0, which omits the l= tag and hashes the entire canonicalized body.
l= tag.DkimCanon
const char *dkimCanon(void);
void put_DkimCanon(const char *newVal);
Specifies the DKIM canonicalization algorithm used for both signed header fields and the message body. The default is relaxed.
| Value | Behavior |
|---|---|
simple | Preserves header and body formatting closely. Small changes in whitespace or line folding can invalidate the signature. |
relaxed | Normalizes defined whitespace and header-name differences, making the signature more tolerant of harmless transport formatting changes. |
DkimDomain
const char *dkimDomain(void);
void put_DkimDomain(const char *newVal);
Specifies the signing domain written to the d= tag of the generated DKIM-Signature header. The corresponding public key is normally published in DNS under the name formed from DkimSelector and this domain.
From domain for DKIM verification itself. DMARC separately evaluates whether the authenticated DKIM domain is aligned with the message's From domain.DkimHeaders
const char *dkimHeaders(void);
void put_DkimHeaders(const char *newVal);
A colon-separated list of header field names to include in the DKIM signature. These names are written to the signature's h= tag and determine which message headers are protected. The default is:
mime-version:date:message-id:subject:from:to:content-typeHeader field names are case-insensitive. A field name may be listed more than once when multiple instances of the same header are to be signed.
From header. Sign stable, meaningful headers such as Date, Subject, To, and Message-ID. Avoid signing transport-added or commonly modified fields such as Received and Return-Path.DkimSelector
const char *dkimSelector(void);
void put_DkimSelector(const char *newVal);
Specifies the selector written to the s= tag of a generated DKIM signature. The selector and DkimDomain form the DNS name used to locate the public key:
selector._domainkey.signing-domainFor example, selector
reykjavik and domain example-code.com produce the DNS name reykjavik._domainkey.example-code.com.
SetDkimPrivateKey must match the public key published for this selector and domain.HeartbeatMs
void put_HeartbeatMs(int newVal);
Specifies the interval, in milliseconds, between AbortCheck event callbacks during methods that support progress callbacks. Set to 0 to disable these periodic callbacks. The default is 0.
A smaller interval makes cancellation checks more responsive but increases callback overhead.
LastErrorHtml
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
void put_LastMethodSuccess(bool newVal);
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Utf8
void put_Utf8(bool newVal);
When set to true, all const char * arguments and return values are interpreted as UTF-8 strings. When set to false, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is true. Before v11.0.0, it was false.
VerboseLogging
void put_VerboseLogging(bool newVal);
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
VerifyInfo
Contains JSON describing the most recent DKIM or DomainKeys verification attempt. The information may include the signing domain, selector, public key, canonicalization, algorithm, signed headers, and whether verification succeeded.
{
"domain": "amazonses.com",
"selector": "7v7vs6w47njt4pimodk5mmttbegzsi6n",
"publicKey": "MIGfMA0GCSq...z6uqeQIDAQAB",
"canonicalization": "relaxed/simple",
"algorithm": "rsa-sha256",
"signedHeaders": "Subject:From:To:Date:Mime-Version:Content-Type:References:Message-Id:Feedback-ID",
"verified": "yes"
}
This property is updated by DkimVerify and DomainKeyVerify.
Version
Methods
DkimSign
Creates a DKIM-Signature header and prepends it to the MIME message stored in mimeData. The BinData is modified in place.
Before calling this method:
- Set
DkimDomainandDkimSelector. - Load the matching private key by calling
SetDkimPrivateKey. - Configure the algorithm, canonicalization, signed headers, and optional body-length setting as needed.
Returns true for success, false for failure.
DkimVerify
Verifies the DKIM signature at zero-based index sigIndex in the MIME message stored in mimeData. Use NumDkimSigs to determine how many DKIM-Signature headers are present.
Chilkat uses a matching cached key when available; otherwise it retrieves the public key identified by the signature's selector and signing domain. After the call, inspect VerifyInfo for details about the signature and verification result.
Returns true for success, false for failure.
LoadPublicKey
Caches an RSA public key for the specified selector and domain. When a later DKIM or DomainKeys verification references the same selector and domain, Chilkat can use this cached key instead of retrieving the key from DNS.
The publicKey argument contains the key in a supported textual representation, such as PEM or XML. Chilkat detects the format automatically.
Returns true for success, false for failure.
topLoadPublicKeyFile
Loads and caches an RSA public key from the local file specified by publicKeyFilepath for the given selector and domain. Chilkat detects the supported key-file format automatically.
When a later DKIM or DomainKeys verification references the same selector and domain, the cached key can be used instead of performing a DNS lookup.
publicKeyFilepath is a path in the local filesystem. Only load keys from a trusted source because supplying an incorrect key changes which signatures can be accepted for that selector and domain.Returns true for success, false for failure.
topLoadTaskCaller
Loads the original caller object associated with the asynchronous task. This is an internal support method used by Chilkat's asynchronous task infrastructure and is not normally needed in application code.
Returns true for success, false for failure.
topNumDkimSigs
Returns the number of DKIM-Signature header fields found in the MIME message stored in mimeData. Signature indexes passed to DkimVerify are zero-based and range from 0 through one less than this count.
PrefetchPublicKey
Retrieves and caches the public key for the specified selector and domain. The DNS lookup is made for:
selector._domainkey.domainCall this method before verifying messages when the application expects many signatures from the same selector and domain. It may be called multiple times for different selector/domain pairs.
DkimVerify and DomainKeyVerify use a matching cached key when available.
Returns true for success, false for failure.
topPrefetchPublicKeyAsync (1)
Creates an asynchronous task to call the PrefetchPublicKey method with the arguments provided.
Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.
Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.
Returns NULL on failure
SetDkimPrivateKey
Associates the RSA privateKey with this object for subsequent calls to DkimSign.
selector._domainkey.domain, using the values in DkimSelector and DkimDomain. Protect the private key as a signing credential and rotate it if exposure is suspected.Returns true for success, false for failure.
topEvents
To implement an event callback, your application would define and implement a class that inherits from CkBaseProgress. Your application can implement methods to override some or all of the default/empty method implementations of the CkBaseProgress base class.
For example:
CkDkim dkim; MyDkimProgress callbackObj; dkim.put_EventCallbackObject(&callbackObj);
MyDkimProgress example:
#include "CkBaseProgress.h"
class MyDkimProgress : public CkBaseProgress {
public:
MyDkimProgress();
virtual ~MyDkimProgress();
void AbortCheck(bool *abort);
void PercentDone(int pctDone, bool *abort);
void ProgressInfo(const char *name, const char *value);
void TaskCompleted(CkTask &task);
};AbortCheck
Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.
PercentDone
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
ProgressInfo
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
TaskCompleted
Called from the background thread when an asynchronous task completes.
Deprecated
DomainKeyAlg
const char *domainKeyAlg(void);
void put_DomainKeyAlg(const char *newVal);
Specifies the algorithm used when creating a legacy DomainKey-Signature header. The only supported value, and the default, is rsa-sha1.
rsa-sha256 unless compatibility with an older system specifically requires DomainKeys.DomainKeyCanon
const char *domainKeyCanon(void);
void put_DomainKeyCanon(const char *newVal);
Specifies the canonicalization algorithm used when creating a legacy DomainKey-Signature header. The default is nofws.
| Value | Meaning |
|---|---|
simple | Uses the message representation with minimal normalization. |
nofws | Applies the DomainKeys no-folding-whitespace canonicalization rules. |
DkimCanon.DomainKeyDomain
const char *domainKeyDomain(void);
void put_DomainKeyDomain(const char *newVal);
Specifies the signing domain written to a legacy DomainKey-Signature header. Together with DomainKeySelector, it identifies the DNS location of the DomainKeys public key.
DkimDomain for new DKIM implementations.DomainKeyHeaders
const char *domainKeyHeaders(void);
void put_DomainKeyHeaders(const char *newVal);
A colon-separated list of header field names to include in a legacy DomainKeys signature. The default is:
mime-version:date:message-id:subject:from:to:content-type
DkimHeaders.DomainKeySelector
const char *domainKeySelector(void);
void put_DomainKeySelector(const char *newVal);
Specifies the selector used to locate the public key for a legacy DomainKeys signature. The DNS name is formed as:
selector._domainkey.signing-domainFor example, selector
reykjavik and domain example-code.com produce reykjavik._domainkey.example-code.com.
DkimSelector.DomainKeySign
Creates a legacy DomainKey-Signature header and prepends it to the MIME message stored in mimeData. The BinData is modified in place.
Before calling this method, set DomainKeyDomain and DomainKeySelector, and load the matching private key by calling SetDomainKeyPrivateKey.
DkimSign for modern email authentication.Returns true for success, false for failure.
topDomainKeyVerify
Verifies the legacy DomainKeys signature at zero-based index sigIndex in the MIME message stored in mimeData. Use NumDomainKeySigs to determine how many DomainKey-Signature headers are present.
After the call, inspect VerifyInfo for details about the signature and verification result.
Returns true for success, false for failure.
NumDomainKeySigs
Returns the number of legacy DomainKey-Signature header fields found in the MIME message stored in mimeData. Signature indexes passed to DomainKeyVerify are zero-based and range from 0 through one less than this count.
DKIM-Signature headers. Use NumDkimSigs for DKIM.SetDomainKeyPrivateKey
Associates the RSA privateKey with this object for subsequent calls to DomainKeySign.
SetDkimPrivateKey and DkimSign.Returns true for success, false for failure.
top