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) Load PFX/P12 from a Base64 Encoded PFX FileDemonstrates how to call LoadPfxEncoded.
-- 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 @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/pfx/cert_test123.pfx' IF @success <> 1 BEGIN PRINT 'Failed to load PFX file.' EXEC @hr = sp_OADestroy @bd RETURN END -- Get the bytes contained in the PFX in base64 format: DECLARE @strBase64 nvarchar(4000) EXEC sp_OAMethod @bd, 'GetEncoded', @strBase64 OUT, 'base64' -- The base64 looks like this: "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..." PRINT @strBase64 DECLARE @pfx int -- Use "Chilkat_9_5_0.Pfx" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Pfx', @pfx OUT -- Load the PFX from the base64 string DECLARE @password nvarchar(4000) SELECT @password = 'test123' EXEC sp_OAMethod @pfx, 'LoadPfxEncoded', @success OUT, @strBase64, 'base64', @password IF @success <> 1 BEGIN EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pfx RETURN END PRINT 'success' EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @pfx END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.