Unicode C
Unicode C
MIME S/MIME Signing Algorithm Properties
See more MIME Examples
Demonstrates the properties that control S/MIME signing: SigningAlg (the RSA signature scheme, PKCS1-V1_5 or RSASSA-PSS), SigningHashAlg (the message-digest algorithm), Micalg and Protocol (the micalg and protocol parameters of a multipart/signed Content-Type), and UseXPkcs7 (whether historical x-pkcs7 media-type names are used). The properties are configured before creating a detached signature.
Background. These settings determine how the CMS/PKCS #7 signature is produced and how a multipart/signed wrapper advertises it. The defaults (PKCS1-V1_5, sha256) suit most modern uses; the properties allow interoperability with specific requirements.
Chilkat Unicode C Downloads
#include <C_CkMimeW.h>
#include <C_CkCertW.h>
void ChilkatSample(void)
{
BOOL success;
HCkMimeW mime;
const wchar_t *pfxPassword;
HCkCertW cert;
success = FALSE;
mime = CkMimeW_Create();
success = CkMimeW_SetBodyFromPlainText(mime,L"This message will be signed.");
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
return;
}
// SigningAlg is the RSA signature scheme. The default is PKCS1-V1_5; set RSASSA-PSS (or pss) for
// RSASSA-PSS.
CkMimeW_putSigningAlg(mime,L"PKCS1-V1_5");
// SigningHashAlg is the message-digest algorithm. The default is sha256.
CkMimeW_putSigningHashAlg(mime,L"sha256");
// Micalg and Protocol are the micalg and protocol parameters written into a multipart/signed
// Content-Type header field. They are normally set automatically, but can be controlled here.
CkMimeW_putMicalg(mime,L"sha-256");
CkMimeW_putProtocol(mime,L"application/pkcs7-signature");
// UseXPkcs7 controls whether newly created S/MIME media types use the historical x-pkcs7 names.
CkMimeW_putUseXPkcs7(mime,FALSE);
// Load a signing certificate (with private key access) from a PFX. The PFX password should come
// from a secure source rather than being hard-coded.
pfxPassword = L"myPfxPassword";
cert = CkCertW_Create();
success = CkCertW_LoadPfxFile(cert,L"qa_data/signer.pfx",pfxPassword);
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
return;
}
// Create the detached signature using the algorithms configured above.
success = CkMimeW_AddDetachedSignature(mime,cert);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
return;
}
wprintf(L"Signed with SigningAlg=%s SigningHashAlg=%s\n",CkMimeW_signingAlg(mime),CkMimeW_signingHashAlg(mime));
CkMimeW_Dispose(mime);
CkCertW_Dispose(cert);
}