Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

SQL Server Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(SQL Server) Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

How to create a PKCS12 (.p12 or .pfx) from a certificate file and private key file: Demonstrates how to duplicate this OpenSSL command:

Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int

    --  The PFX class requires the software to be unlocked..
    DECLARE @global int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Global', @global OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @global, 'UnlockBundle', @success OUT, 'Anything for 30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @global, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        RETURN
      END

    DECLARE @pkey int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.PrivateKey', @pkey OUT

    --  Load the private key from the file.
    --  There are several methods for loading private keys from a file:
    --      LoadPkcs8File
    --      LoadRsaDerFile
    --      LoadPemFile
    --      LoadPvkFile
    --      LoadXmlFile
    --  In actuality, it doesn't matter which one is called. In all cases
    --  Chilkat will automatically recognize the format of the private key
    --  file and load it correctly.  Therefore, even if actual contents
    --  of the file does not agree with the name of the method, it will still work.
    --  The only way it won't work is if it's not actually a private key file
    --  (perhaps it is only a public key file), or perhaps the private key
    --  file is encrypted and requires a password.  In that case, you would
    --  call one of the Chilkat methods to load the encrypted private key file
    --  (and these methods include an argument to specify the password).
    EXEC sp_OAMethod @pkey, 'LoadPkcs8File', @success OUT, 'certFile.key'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pkey, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        EXEC @hr = sp_OADestroy @pkey
        RETURN
      END

    DECLARE @cert int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Cert', @cert OUT

    --  The LoadFromFile method auto-recognizes the format...
    EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'certfile.cer'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        EXEC @hr = sp_OADestroy @pkey
        EXEC @hr = sp_OADestroy @cert
        RETURN
      END

    --  We'll need a cert chain object to create the PKCS12, so get it
    --  from the cert.
    DECLARE @certChain int

    EXEC sp_OAMethod @cert, 'GetCertChain', @certChain OUT
    EXEC sp_OAGetProperty @cert, 'LastMethodSuccess', @iTmp0 OUT
    IF Not @iTmp0
      BEGIN
        EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        EXEC @hr = sp_OADestroy @pkey
        EXEC @hr = sp_OADestroy @cert
        RETURN
      END

    --  Create the PFX object, add the cert and private key, and write to a .pfx file.
    DECLARE @pfx int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Pfx', @pfx OUT

    --  The cert(s) are automatically added in the call to AddPrivateKey
    EXEC sp_OAMethod @pfx, 'AddPrivateKey', @success OUT, @pkey, @certChain
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        EXEC @hr = sp_OADestroy @pkey
        EXEC @hr = sp_OADestroy @cert
        EXEC @hr = sp_OADestroy @pfx
        RETURN
      END

    --  Write the .pfx to a file.
    DECLARE @password nvarchar(4000)
    SELECT @password = 'myPassword'
    EXEC sp_OAMethod @pfx, 'ToFile', @success OUT, @password, 'certfile.pfx'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pfx, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @global
        EXEC @hr = sp_OADestroy @pkey
        EXEC @hr = sp_OADestroy @cert
        EXEC @hr = sp_OADestroy @pfx
        RETURN
      END


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @global
    EXEC @hr = sp_OADestroy @pkey
    EXEC @hr = sp_OADestroy @cert
    EXEC @hr = sp_OADestroy @pfx


END
GO

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.