Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
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 Unicode C++ Downloads
#include <CkEmailW.h>
#include <CkCertW.h>
#include <CkMailManW.h>
#include <CkBinDataW.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmailW email;
success = email.LoadEml(L"message.eml");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
CkCertW cert;
success = cert.LoadPfxFile(L"signer.pfx",L"PFX_PASSWORD");
if (success != true) {
wprintf(L"%s\n",cert.lastErrorText());
return;
}
success = email.SetSigningCert(cert);
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
email.put_SigningAlg(L"pss");
email.put_SigningHashAlg(L"sha256");
email.put_SendSigned(true);
CkMailManW mail;
mail.put_OpaqueSigning(false);
CkBinDataW rendered;
success = mail.RenderToMimeBd(email,rendered);
if (success != true) {
wprintf(L"%s\n",mail.lastErrorText());
return;
}
success = rendered.WriteFile(L"signed.eml");
if (success != true) {
wprintf(L"Failed: rendered.WriteFile.\n");
return;
}
wprintf(L"Saved signed.eml.\n");
}