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) Load ECC Public Key from JWK Format (JSON Web Key)

Demonstrates how to load an ECC public key from JWK (JSON Web Key) format.

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

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)
    -- Note: This example requires Chilkat v9.5.0.66 or later.
    DECLARE @success int

    -- First build a JWK sample to load..
    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'kty', 'EC'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'crv', 'P-256'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'x', 'oBUyo8CQAFPeYPvv78ylh5MwFZjTCLQeb042TjiMJxE'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'y', 'vvQyxZkUjJQUPU_0bCy3Pj5qQdfu8jwEfqEeYGZ95CU'

    -- The JSON contains the following:
    -- { 
    --   "kty": "EC",
    --   "crv": "P-256",
    --   "x": "oBUyo8CQAFPeYPvv78ylh5MwFZjTCLQeb042TjiMJxE",
    --   "y": "vvQyxZkUjJQUPU_0bCy3Pj5qQdfu8jwEfqEeYGZ95CU",
    -- }

    -- Note: The JSON can contain other members, such as "use", "kid", or anything else.  These will be ignored.
    EXEC sp_OASetProperty @json, 'EmitCompact', 0

    -- Show the JWK string to be loaded:
    DECLARE @jwkStr nvarchar(4000)
    EXEC sp_OAMethod @json, 'Emit', @jwkStr OUT

    DECLARE @pubKey int
    -- Use "Chilkat_9_5_0.PublicKey" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.PublicKey', @pubKey OUT

    -- The LoadFromString method will automatically detect the format.
    EXEC sp_OAMethod @pubKey, 'LoadFromString', @success OUT, @jwkStr
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @pubKey, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @pubKey
        RETURN
      END

    -- OK.. the JWK is loaded.  It can be used in whatever way desired...

    -- The key can be retrieved in any other format, such as XML or PEM..
    EXEC sp_OAMethod @pubKey, 'GetXml', @sTmp0 OUT
    PRINT @sTmp0

    -- XML output:
    -- <ECCPublicKey curve="secp256r1" 
    --    x="A01532A3C0900053DE60FBEFEFCCA58793301598D308B41E6F4E364E388C2711" 
    --    y="BEF432C599148C94143D4FF46C2CB73E3E6A41D7EEF23C047EA11E60667DE425">
    --    MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAAAAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA///////////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSdNgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA//////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABKAVMqPAkABT3mD77+/MpYeTMBWY0wi0Hm9ONk44jCcRvvQyxZkUjJQUPU/0bCy3Pj5qQdfu8jwEfqEeYGZ95CU=
    -- </ECCPublicKey>

    -- Choose PCKS1 or PCKS8 PEM format..
    DECLARE @bPreferPkcs1 int
    SELECT @bPreferPkcs1 = 0
    EXEC sp_OAMethod @pubKey, 'GetPem', @sTmp0 OUT, @bPreferPkcs1
    PRINT @sTmp0

    -- PEM output
    -- -----BEGIN PUBLIC KEY-----
    -- MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
    -- AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
    -- ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
    -- NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
    -- RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
    -- //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABKAVMqPAkABT3mD77+/MpYeT
    -- MBWY0wi0Hm9ONk44jCcRvvQyxZkUjJQUPU/0bCy3Pj5qQdfu8jwEfqEeYGZ95CU=
    -- -----END PUBLIC KEY-----

    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @pubKey


END
GO

 

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