SQL Server
SQL Server
Example: Crypt2.SetSigningCert method
Demonstrates how to call the SetSigningCert method.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @success int
SELECT @success = 0
-- Signing certificates can be obtained from many different sources..
-- Load from a PFX
DECLARE @cryptA int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @cryptA OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @certA int
EXEC @hr = sp_OACreate 'Chilkat.Cert', @certA OUT
EXEC sp_OAMethod @certA, 'LoadPfxFile', @success OUT, 'c:/someDir/pfx_files/a.pfx', 'pfx_file_password'
EXEC sp_OAMethod @cryptA, 'SetSigningCert', @success OUT, @certA
-- ...
-- Load from a smart card or USB token.
DECLARE @cryptB int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @cryptB OUT
DECLARE @certB int
EXEC @hr = sp_OACreate 'Chilkat.Cert', @certB OUT
EXEC sp_OASetProperty @certB, 'SmartCardPin', '123456'
EXEC sp_OAMethod @certB, 'LoadFromSmartcard', @success OUT, ''
EXEC sp_OAMethod @cryptB, 'SetSigningCert', @success OUT, @certB
-- ...
-- Load from a the Windows certificate store or macOS keychain
DECLARE @cryptC int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @cryptC OUT
DECLARE @certC int
EXEC @hr = sp_OACreate 'Chilkat.Cert', @certC OUT
EXEC sp_OAMethod @certC, 'LoadByCommonName', @success OUT, 'Xyz 123'
EXEC sp_OAMethod @cryptC, 'SetSigningCert', @success OUT, @certC
-- ...
EXEC @hr = sp_OADestroy @cryptA
EXEC @hr = sp_OADestroy @certA
EXEC @hr = sp_OADestroy @cryptB
EXEC @hr = sp_OADestroy @certB
EXEC @hr = sp_OADestroy @cryptC
EXEC @hr = sp_OADestroy @certC
END
GO