Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) Export Private Keys from Java KeyStore to JWK Set

Demonstrates how to export the private keys from a Java KeyStore to a JWK Set. Each private key alias is exported to the "kid" parameter.

Note: This example requires Chilkat v9.5.0.66 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- 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)
    -- This requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    -- Note: This example requires Chilkat v9.5.0.66 or greater.

    DECLARE @jks int
    -- Use "Chilkat_9_5_0.JavaKeyStore" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JavaKeyStore', @jks OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @jksPassword nvarchar(4000)
    SELECT @jksPassword = 'secret'

    -- Load the Java keystore from a file.  The JKS file password is used
    -- to verify the keyed digest that is found at the very end of the keystore.
    -- It verifies that the keystore has not been modified.
    DECLARE @success int
    EXEC sp_OAMethod @jks, 'LoadFile', @success OUT, @jksPassword, 'qa_data/jks/test_secret.jks'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @jks, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @jks
        RETURN
      END

    -- Export to JWK Set format.
    -- (Exports the compact 1-line JSON string to a StringBuilder..)
    DECLARE @sbJwkSet int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbJwkSet OUT

    EXEC sp_OAMethod @jks, 'ToJwkSet', @success OUT, @jksPassword, @sbJwkSet
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @jks, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @jks
        EXEC @hr = sp_OADestroy @sbJwkSet
        RETURN
      END

    -- To get in human-readable format, load into a JSON object and emit non-compact.
    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbJwkSet
    EXEC sp_OASetProperty @json, 'EmitCompact', 0
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    -- Sample output:

    -- { 
    --   "keys": [
    --     { 
    --       "kty": "RSA",
    --       "n": "yADdNtY3GcgAfwUhvf-ETRbcLFUaecY7lR9UWvBPW6zbzgvUwJRIcxadWFmtFXGZKxLXjKUmNjH8bm9d-cv2l1am1_s-FJN05qxGGNYvQ8EE6BFIkbgREMtpJ9F_BRjuurcIiilYGZ7FxMZDWb5Y5PLmW3JWJzUcCBgchMThzn68m0YpJjxqiVO1LLA-zULccjYyYXpSo0VWNxxaedm7DkJujADJ0-fKtX82vtGKnj8-zvF72CZf_DMhIirIK4Ryzz23-LbNY0b0BS_IQxybZxWpiI8hptciUIaIBIszii-0q3VH5pw0qL8Ec4BiA9pDzThgad3LBdySA-RcPxym6Q",
    --       "e": "AQAB",
    --       "d": "U63o4DSoQSUo7_wZrgDmPcq-u92vghuqei3tgU7iJR0hqgfRL_Hajix8EKcUf9BToW30uWevoSUw1JPL4eOwfIlIrTz1MG6xjoGtol6az-JGR0JT9oPov_obOQmx91QDLiO-cu_xaGbBoB7Dtxyo3MG0F7ayzRyvacOMyxAE2fv24ypb2cYiVNKrsYIGm1QvXvsbkBHW9cCxTSRR3J-jKeYt6X2Lge08z6XpuT7i-a1F_fPKRPWzMwgW1AunHa5GZBAuFZt3_Nv5Gg1RcIOZbax4Xm_7plSFXs76byDFrDQbx9KthTLdGRblRlXMaWmtGBHAmPqcAP45zRCLEO53cQ",
    --       "p": "8uWk3bslzAYbtpxbQumWqIIeMurtH5CEOQv1NzGYLb8q4JRp9mysG1gsJk9_D5-JyqYZd4jkCj9pHgrY5q4J9LmVtJMUsl7m7qp7zqgWK2Q1pOTFH7bwa7omGUqqmSYJdA6rWqq3hiOPOtu5uQgZA0zZCX6o8Y19E55jdI1qM2M",
    --       "q": "0sreI4hZKsC3crSA026bfAWBsqbwBgBr06gOiWl6p4xTRV8dVUtKyMA51_CRSu06oQ4zP6TRGnbPq9CHJIMRN15hX7J5iLJA-ApjgFRItPAvUeEkxha9CfwtCMEqw0Zea1-FH-mLQZ9nJeXyoHnjBpmz_pKE-5HlbJbtKsCCPEM",
    --       "dp": "I2UPZzg0Q8zIEQ4rxk5fo-KCIA1XzHe0rNNvQkG52UC4MM2vuzcOxVVN6a8_5rjqzVry7xZFlLC00qnl_Ydy7_RzOkMMiwmFQVYagHzB7kTGBGdJyltQIYKYtqrIvVRroDvbAHVMFQHthzgpkir56h8yqU2JtNlXVpqIB53r0d0",
    --       "dq": "zGHXMSyrCEEDnjxWDKtaJs5QCyDB6Y_O_NIeBi43tuzgcIrgrirqv-tiKnYe6j9KcY6LMlJkTPyWL0lpP4W107G3SEqMfHYZeGbaQzt1o7qepw1d0pOJh3zzTWG-TMiWFBXxxhdz5pTgNmbW8bI85dFyLIt0VVgI01kjbChsHnE",
    --       "qi": "52wp71nLXtQwu7bH-yYp8No4ru3Vbr6BjzzN7kXTwxLmalzQFRkDUcKzYuOpwgJwCj0REsAnIGXKT4p6PXouzxGFad7dFEINrt3ezXUkN0HVobu0GoOTjlQqJHrkDJM111UVrAgQlr7BVIsx_FbE9hbpGlkeTmim_FCBa12CJhY",
    --       "kid": "test"
    --     },
    --     { 
    --       "kty": "EC",
    --       "crv": "P-256",
    --       "x": "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
    --       "y": "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
    --       "d": "870MB6gfuTJ4HtUnUvYMyJpr5eUZNP4Bk43bVdj3eAE",
    --       "kid": "1"
    --     }
    --   ]
    -- }

    EXEC @hr = sp_OADestroy @jks
    EXEC @hr = sp_OADestroy @sbJwkSet
    EXEC @hr = sp_OADestroy @json


END
GO

 

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