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

DataFlex 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
Async
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
Secrets
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

 

 

 

(DataFlex) Compute JWK Thumbprint for RSA and EC Private Keys

Demonstrates how to compute a JSON Web Key thumbprint for a private key (RSA or ECC).

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoPrivKey
    Handle hoSbPem
    Boolean iBCrlf
    Boolean iSuccess
    Boolean iSuccess
    String sTemp1

    Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
    If (Not(IsComObjectCreated(hoPrivKey))) Begin
        Send CreateComObject of hoPrivKey
    End

    // A private key can be loaded from any format (binary DER, PEM, etc.)
    // This example will load the private keys from PEM format, 
    // and will then compute the JWK thumbprint.

    // First do it for this RSA private key...

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPem
    If (Not(IsComObjectCreated(hoSbPem))) Begin
        Send CreateComObject of hoSbPem
    End
    Move True To iBCrlf
    Get ComAppendLine Of hoSbPem "-----BEGIN RSA PRIVATE KEY-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "Proc-Type: 4,ENCRYPTED" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "DEK-Info: DES-EDE3-CBC,2E65118E6C7B5207" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "7cYUTW4ZBdmVZ4ILB08hcTdm5ib0E0zcy+I7pHpNQfJHtI7BJ4omys5S19ufJPBJ" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "IzYjeO7oTVqI37F6EUmjZqG4WVE2UQbQDkosZbZN82O4Ipu1lFAPEbwjqePMKufz" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "snSQHKfnbyyDPEVNlJbs19NXC8v6g+pQay5rH/I6N2iBxgsTmuemZ54EhNQMZyEN" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "R/CiheArWEH9H8/4hd2gc9Tb2s0MwGHILL4kbbNm5tp3xw4ik7OYWNrj3m+nG6Xb" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "vKXh2xEanAZAyMXTqDJTHdn7/CEqusQPJjZGV+Mf1kjKu7p4qcXFnIXP5ILnTW7b" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "lHoWC4eweDzKOMRzXmbABEVSUvx2SmPl4TcoC5L1SCAHEmZaKbaY7S5l53u6gl0f" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "ULuQbt7Hr3THznlNFKkGT1/yVNt2QOm1emZd55LaNe8E7XsNSlhl0grYQ+Ue8Jba" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "x85OapltVjxM9wVCwbgFyi04ihdKHo9e+uYKeTGKv0hU5O7HEH1ev6t/s2u/UG6h" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "TqEsYrVp0CMHpt5uAF6nZyK6GZ/CHTxh/rz1hADMofem59+e6tVtjnPGA3EjnJT8" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "BMOw/D2QIDxjxj2GUzz+YJp50ENhWrL9oSDkG2nzv4NVL77QIy+T/2/f4PgokUDO" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "QJjIfxPWE40cHGHpnQtZvEPoxP0H3T0YhmEVwuJxX3uaWOY/8Fa1c7Ln0SwWdfV5" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "gYvJV8o6c3sumcq1O3agPDlHC5O4IxG7AZQ8CHRDyASogzfkY6P579ZOGYaO4al7" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "WA1YIpsHs3/1f4SByMuWe0NVkFfvXckjpqGrBQpTmqQzk6baa0VQ0cwU3XlkwHac" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "WB/fQ4jylwFzZDcp5JAo53n6aU72zgNvDlGTNKwdXXZI5U3JPocH0AiZgFFWYJLd" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "63PJLDnjyE3i6XMVlxifXKkXVv0RYSz+ByS7Oz9aCgnQhNU8ycv+UxtfkPQih5zE" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "/0Y2EEFknajmFJpNXczzF8OEzaswmR0AOjcCiklZKRf61rf5faJxJhhqKEEBJuL6" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "oodDVRk3OGU1yQSBazT8nK3V+e6FMo3tWkra2BXFCD+pKxTy014Cp59S1w6F1Fjt" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "WX7eMWSLWfQ56j2kLMBHq5gb2arqlqH3fsYOTD3TNjCYF3Sgx309kVPuOK5vw61P" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "pnL/LN3iGY42WR+9lfAyNN2qj9zvwKwscyYs5+DPQoPmcPcVGc3v/u66bLcOGbEU" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "OlGa/6gdD4GCp5E4fP/7GbnEY/PW2abquFhGB+pVdl3/4+1U/8kItlfWNZoG4FhE" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "gjMd7glmrdFiNJFFpf5ks1lVXGqJ4mZxqtEZrxUEwciZjm4V27a+E2KyV9NnksZ6" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "xF4tGPKIPsvNTV5o8ZqjiacxgbYmr2ywqDXKCgpU/RWSh1sLapqSQqbH/w0MquUj" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "VhVX0RMYH/foKtjagZf/KO1/mnCITl86treIdachGgR4wr/qqMjrpPUaPLCRY3JQ" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "00XUP1Mu6YPE0SnMYAVxZheqKHly3a1pg4Xp7YWlM671oUORs3+VENfnbIxgr+2D" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "TiJT9PxwpfK53Oh7RBSWHJZRuAdLUXE8DG+bl0N/QkJM6pFUxTI1AQ==" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "-----END RSA PRIVATE KEY-----" iBCrlf To iSuccess

    // The actual password for the above PEM is "passwd".
    Get ComGetAsString Of hoSbPem To sTemp1
    Get ComLoadEncryptedPem Of hoPrivKey sTemp1 "passwd" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPrivKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Generate the JWK thumbprint:
    Get ComGetJwkThumbprint Of hoPrivKey "SHA256" To sTemp1
    Showln "JWK thumbprint: " sTemp1

    // Output:
    // JWK thumbprint: QzUpUAW1Y5iksGxq3r1o3JMROR6D7FLwvRlHmDQVg0I

    // --------------------------------------------------------------
    // Now let's do an EC private key.  The following is an unencrypted PEM containing a 384-bit EC key..
    Send ComClear To hoSbPem
    Get ComAppendLine Of hoSbPem "-----BEGIN PRIVATE KEY-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDAamStb0Xep3y3sWw2u" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "SSAdUPkgQ9Rvhlnx8XEVOYy2teh69T0on77ja02m03n8t8WhZANiAARUNSar38Rz" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "lKPyZFsNSGUanzpNRth0C+MikVEH8FAlDHMMpAs34dyF4IK0uxgbiEe9bQ+ieLrl" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "6xwFR0yaTivuwoyXC+ScGUnwnpaXmid6UUgw4ypbneHsaKuZ9JLdMAo=" iBCrlf To iSuccess
    Get ComAppendLine Of hoSbPem "-----END PRIVATE KEY-----" iBCrlf To iSuccess

    Get ComGetAsString Of hoSbPem To sTemp1
    Get ComLoadPem Of hoPrivKey sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPrivKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Generate the JWK thumbprint:
    Get ComGetJwkThumbprint Of hoPrivKey "SHA256" To sTemp1
    Showln "JWK thumbprint: " sTemp1

    // Output:
    // JWK thumbprint: ABAUUfNSONFsZYvZ_o_0bsPT3qeG3jttXB09VC_ETWQ


End_Procedure

 

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