SQL Server
SQL Server
Load a PFX from an Encoded String
See more PFX/P12 Examples
Demonstrates Pfx.LoadPfxEncoded, which decodes text using a named binary encoding (such as base64) and loads the resulting bytes as a PFX / PKCS#12 container.
Background. This is useful when the PKCS#12 data has been transported or stored as printable text, such as base64.
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 @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @pfx int
EXEC @hr = sp_OACreate 'Chilkat.Pfx', @pfx OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The PFX password should come from a secure source rather than being hard-coded.
DECLARE @password nvarchar(4000)
SELECT @password = 'myPfxPassword'
-- Decode the base64 text into PFX / PKCS#12 bytes and load them. Common encodings include base64
-- and hex.
DECLARE @encodedPfx nvarchar(4000)
SELECT @encodedPfx = 'MIIKrAIBAzCCCm...base64-encoded-pfx...'
EXEC sp_OAMethod @pfx, 'LoadPfxEncoded', @success OUT, @encodedPfx, 'base64', @password
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @pfx
RETURN
END
EXEC sp_OAGetProperty @pfx, 'NumCerts', @iTmp0 OUT
PRINT 'Loaded ' + @iTmp0 + ' certificate(s).'
EXEC @hr = sp_OADestroy @pfx
END
GO