Sample code for 30+ languages & platforms
SQL Server

Convert DSA Public Key DER to PEM

See more DSA Examples

Converts a DSA public key from DER format to PEM.

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

    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

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

    -- Load a DER public key.
    EXEC sp_OAMethod @dsa, 'FromPublicDerFile', @success OUT, 'dsa_pub.der'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @dsa, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @dsa
        RETURN
      END

    DECLARE @pemStr nvarchar(4000)

    -- Save the public key to PEM:
    EXEC sp_OAMethod @dsa, 'ToPublicPem', @pemStr OUT
    EXEC sp_OAMethod @dsa, 'SaveText', @success OUT, @pemStr, 'dsa_pub.pem'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @dsa, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @dsa
        RETURN
      END


    PRINT 'Finished!'

    EXEC @hr = sp_OADestroy @dsa


END
GO