C++
C++
Select the Hash Algorithm for Signed Email
See more Email Object Examples
Demonstrates the Chilkat Email.SigningHashAlg property, which selects the underlying hash algorithm used when sending signed (PKCS#7) email. Possible values are sha1, sha256, sha384, sha512, md5, and md2; the default is sha1. It controls the message-digest algorithm placed in the signature and is used only when a signed message is generated. This example selects SHA-256.
Background: A digital signature does not sign the whole message directly — it signs a hash, a short fixed-length fingerprint computed from the content. The hash algorithm's job is to make it infeasible to find two different messages with the same fingerprint. Older algorithms like
md5 and sha1 are now considered weak (collisions have been demonstrated), so modern signing should prefer sha256 or stronger even though sha1 remains the historical default.Chilkat C++ Downloads
#include <CkEmail.h>
void ChilkatSample(void)
{
// Demonstrates the Email.SigningHashAlg property, which selects the hash (message-digest)
// algorithm used when sending signed (PKCS#7) email. Possible values: sha1, sha256,
// sha384, sha512, md5, md2. The default is sha1.
CkEmail email;
// Select SHA-256 for the signature's message digest.
email.put_SigningHashAlg("sha256");
std::cout << "SigningHashAlg = " << email.signingHashAlg() << "\r\n";
}