(SQL Server) Load a Certificate from the Windows Certificate Store
Demonstrates how to load a certificate that has been pre-installed in the registry-based Windows certificate store. This is generally how one would load a certificate that is stored on a smart card or usb token.
-- 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 @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, 'LoadByCommonName', @success OUT, 'PIVKey 7ED53EC611D3F84396212C5842BB563F'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @cert
RETURN
END
EXEC sp_OAGetProperty @cert, 'SubjectDN', @sTmp0 OUT
PRINT 'Loaded: ' + @sTmp0
EXEC @hr = sp_OADestroy @cert
END
GO
|