Sample code for 30+ languages & platforms
SQL Server

Get an S/MIME Signing Time

See more MIME Examples

Demonstrates the Chilkat Mime.GetSignatureSigningTimeStr method, which returns the CMS signingTime attribute for the signer at a zero-based index, as an RFC 822-style date string in GMT. The only argument is the signer index.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: This is the timestamp the signer asserted at signing — useful for "when was this signed" audit trails and for evaluating whether the signing certificate was valid at that moment. Because it is a signed attribute, it is tamper-evident. Guard the call with HasSignatureSigningTime, since the attribute is optional. Note it is the signer's claim, not a trusted third-party timestamp.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

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

    EXEC sp_OAMethod @mime, 'LoadMimeFile', @success OUT, 'qa_data/signed.eml'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  After verifying, get the CMS signingTime for each signer that has one, as an RFC 822 date string
    --  in GMT.  The only argument is the zero-based signer index.
    EXEC sp_OAMethod @mime, 'Verify', @success OUT
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    DECLARE @n int
    EXEC sp_OAGetProperty @mime, 'NumSignerCerts', @n OUT
    DECLARE @i int

    SELECT @i = 0
    WHILE @i <= @n - 1
      BEGIN
        --  Only signers that included a signing time have one to retrieve.
        EXEC sp_OAMethod @mime, 'HasSignatureSigningTime', @iTmp0 OUT, @i
        IF @iTmp0
          BEGIN
            DECLARE @signingTime nvarchar(4000)
            EXEC sp_OAMethod @mime, 'GetSignatureSigningTimeStr', @signingTime OUT, @i
            EXEC sp_OAGetProperty @mime, 'LastMethodSuccess', @iTmp0 OUT
            IF @iTmp0 = 0
              BEGIN
                EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
                PRINT @sTmp0
                EXEC @hr = sp_OADestroy @mime
                RETURN
              END


            PRINT 'Signer ' + @i + ' signing time: ' + @signingTime
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @mime


END
GO