Sample code for 30+ languages & platforms
SQL Server

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 SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    --  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.

    DECLARE @email int
    EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    --  Select SHA-256 for the signature's message digest.
    EXEC sp_OASetProperty @email, 'SigningHashAlg', 'sha256'


    EXEC sp_OAGetProperty @email, 'SigningHashAlg', @sTmp0 OUT
    PRINT 'SigningHashAlg = ' + @sTmp0

    EXEC @hr = sp_OADestroy @email


END
GO