Sample code for 30+ languages & platforms
SQL Server

Example: Crypt2.LastSignerCert method

Demonstrates how to call the LastSignerCert method.

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
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

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

    DECLARE @p7m_path nvarchar(4000)
    SELECT @p7m_path = 'qa_data/p7m/Firma.docx.p7m'
    DECLARE @out_path nvarchar(4000)
    SELECT @out_path = 'qa_output/Firma.docx'

    EXEC sp_OAMethod @crypt, 'VerifyP7M', @success OUT, @p7m_path, @out_path
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @crypt
        RETURN
      END

    -- Examine the certificate(s) used for signing.
    DECLARE @numSigners int
    EXEC sp_OAGetProperty @crypt, 'NumSignerCerts', @numSigners OUT
    DECLARE @i int
    SELECT @i = 0

    DECLARE @cert int
    EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT

    WHILE @i < @numSigners
      BEGIN
        EXEC sp_OAMethod @crypt, 'LastSignerCert', @success OUT, @i, @cert

        EXEC sp_OAGetProperty @cert, 'SubjectDN', @sTmp0 OUT
        PRINT 'Signer: ' + @sTmp0
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @crypt
    EXEC @hr = sp_OADestroy @cert


END
GO