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 PKCS12 / PFX and Access ContentsLoads a PKCS12 / PFX file and iterates over the contents which include private keys and certificates.
-- 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 -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @pfx int -- Use "Chilkat_9_5_0.Pfx" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Pfx', @pfx OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Load the PKCS12 from a file DECLARE @success int EXEC sp_OAMethod @pfx, 'LoadPfxFile', @success OUT, '/someDir/my.p12', 'pfxFilePassword' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @pfx RETURN END DECLARE @numPrivateKeys int EXEC sp_OAGetProperty @pfx, 'NumPrivateKeys', @numPrivateKeys OUT DECLARE @privKey int PRINT 'Private Keys:' DECLARE @i int SELECT @i = 0 WHILE @i < @numPrivateKeys BEGIN EXEC sp_OAMethod @pfx, 'GetPrivateKey', @privKey OUT, @i -- Do something with the private key ... EXEC @hr = sp_OADestroy @privKey SELECT @i = @i + 1 END DECLARE @cert int DECLARE @numCerts int EXEC sp_OAGetProperty @pfx, 'NumCerts', @numCerts OUT PRINT 'Certs:' SELECT @i = 0 WHILE @i < @numCerts BEGIN EXEC sp_OAMethod @pfx, 'GetCert', @cert OUT, @i EXEC sp_OAGetProperty @cert, 'SubjectDN', @sTmp0 OUT PRINT @sTmp0 -- If the certificate has a private key (one of the private keys within the PFX) -- then it can also be obtained via the certificate object: EXEC sp_OAMethod @cert, 'HasPrivateKey', @iTmp0 OUT IF @iTmp0 = 1 BEGIN PRINT 'Has private key!' EXEC sp_OAMethod @cert, 'ExportPrivateKey', @privKey OUT -- ... EXEC @hr = sp_OADestroy @privKey END EXEC @hr = sp_OADestroy @cert SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @pfx END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.