Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Duplicate OpenSSL smime CommandDemonstrates how to duplicate an OpenSSL smime command to sign a text file using cert + key.
-- 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) -- This requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- This example duplicates the following OpenSSL command: -- -- smime -sign -in helloWorld.txt -signer cert.pem -inkey my.key -passin pass:test1234 -outform PEM -out helloWorldSigned.pem DECLARE @certPath nvarchar(4000) SELECT @certPath = 'qa_data/cert.pem' DECLARE @privateKeyPath nvarchar(4000) SELECT @privateKeyPath = 'qa_data/my.key' DECLARE @password nvarchar(4000) SELECT @password = 'test1234' DECLARE @dataFile nvarchar(4000) SELECT @dataFile = 'qa_data/helloWorld.txt' DECLARE @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, @certPath IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert RETURN END DECLARE @privKey int -- Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.PrivateKey', @privKey OUT EXEC sp_OAMethod @privKey, 'LoadEncryptedPemFile', @success OUT, @privateKeyPath, @password IF @success <> 1 BEGIN EXEC sp_OAGetProperty @privKey, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @privKey RETURN END DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, @dataFile IF @success <> 1 BEGIN PRINT 'Failed to load ' + @dataFile EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @bd RETURN END DECLARE @crypt int -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT EXEC sp_OAMethod @crypt, 'SetSigningCert2', @success OUT, @cert, @privKey IF @success <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @crypt RETURN END EXEC sp_OAMethod @crypt, 'OpaqueSignBd', @success OUT, @bd IF @success <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @crypt RETURN END DECLARE @sbPem int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbPem OUT EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----BEGIN PKCS7-----', 1 EXEC sp_OAMethod @bd, 'GetEncoded', @sTmp0 OUT, 'base64_mime' EXEC sp_OAMethod @sbPem, 'Append', @success OUT, @sTmp0 EXEC sp_OAMethod @sbPem, 'AppendLine', @success OUT, '-----END PKCS7-----', 1 EXEC sp_OAMethod @sbPem, 'WriteFile', @success OUT, 'helloWorldSigned.pem', 'utf-8', 0 EXEC sp_OAMethod @sbPem, 'GetAsString', @sTmp0 OUT PRINT @sTmp0 -- Sample output: -- -----BEGIN PKCS7----- -- MIINxAYJKoZIhvcNAQcCoIINtTCCDbECAQExCzAJBgUrDgMCGgUAMBoGCSqGSIb3DQEHAaANBAtI -- ZWxsbyBXb3JsZKCCC0owggYQMIID+KADAgECAhBNlCwQ1DvglAnFgS06KwZPMA0GCSqGSIb3DQEB -- DAUAMIGIMQswCQYDVQQGEwJVUzETMBEGA1UECBMKTmV3IEplcnNleTEUMBIGA1UEBxMLSmVyc2V5 -- IENpdHkxHjAcBgNVBAoTFVRoZSBVU0VSVFJVU1QgTmV0d29yazEuMCwGA1UEAxMlVVNFUlRydXN0 -- IFJTQSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0xODExMDIwMDAwMDBaFw0zMDEyMzEyMzU5 -- NTlaMIGWMQswCQYDVQQGEwJHQjEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQH -- EwdTYWxmb3JkMRgwFgYDVQQKEw9TZWN0aWdvIExpbWl0ZWQxPjA8BgNVBAMTNVNlY3RpZ28gUlNB -- IENsaWVudCBBdXRoZW50aWNhdGlvbiBhbmQgU2VjdXJlIEVtYWlsIENBMIIBIjANBgkqhkiG9w0B -- AQEFAAOCAQ8AMIIBCgKCAQEAyjztlApB/975Rrno1jvm2pK/KxBOqhq8gr2+JhwpKirSzZxQgT9t -- lC7zl6hn1fXjSo5MqXUfItMltrMaXqcESJuK8dtK56NCSrq4iDKaKq9NxOXFmqXX2zN8HHGjQ2b2 -- Xv0v1L5Nk1MQPKA19xeWQcpGEGFUUd0kN+oHox+L9aV1rjfNiCj3bJk6kJaOPabPi2503nn/ITX5 -- e8WfPnGw4VuZ79Khj1YBrf24k5Ee1s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wgawwgZYxCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIx -- EDAOBgNVBAcTB1NhbGZvcmQxGDAWBgNVBAoTD1NlY3RpZ28gTGltaXRlZDE+MDwGA1UEAxM1U2Vj -- dGlnbyBSU0EgQ2xpZW50IEF1dGhlbnRpY2F0aW9uIGFuZCBTZWN1cmUgRW1haWwgQ0ECEQDwUrMy -- 4rq9PIFHeb0WvDbOMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqG -- SIb3DQEJBTEPFw0xOTA0MDIyMjM2MjRaMCMGCSqGSIb3DQEJBDEWBBQKTVWo13jlAi+rcBl3xdhA -- u8SG0DANBgkqhkiG9w0BAQEFAASCAQAWaz5itTD7L3YUWuRS5nBzJKv6RUe84muwLICW+U5HEEd7 -- aSNXCivMzsIYGN3VpBAfIGbRywDZ8SLFkmR3ernA4y0ki5SUNxfe6s3fsqPVIO56JEEF0/OZ54KU -- 6o/Tn2Qw8mYyYW5n2O690DGqtN/mZjI5vyRM8fG6KDrlnMplACF4St6XZx9Od/Znq039IPzgukJI -- rCIm9n0LFEdSYlajjS/d5GsIKWmy5ktrsXk5Ym6+Um95FBDuwrZyW1qYo+cLAWSBSf9poMUxwQNY -- EAA1iZqJjnlwsgMgM44h9voAW+wDMfcGFUwGDTxaLday6vqxHobR3MwjsBI8qjRbb28G -- -----END PKCS7----- -- -- EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @privKey EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @sbPem END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.