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
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) Load Encrypted PEM Containing ECC Private Key and Certs and Examine Contents

Loads an encrypted PEM containing an ECC private key and ECC certificate (and chain), and examines the contents.

Note: This example requires Chilkat v9.5.0.66.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoSb
    Boolean iBCrlf
    Boolean iSuccess
    Handle hoPem
    Boolean iSuccess
    Variant vPrivKey
    Handle hoPrivKey
    Handle hoJson
    Variant vCert
    Handle hoCert
    String sCertXml
    String sTemp1
    Boolean bTemp1

    // Note: This example requires Chilkat v9.5.0.66.

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Create a PEM containing a valid EC private key and certificates.
    // The password for this encrypted PEM is "secret123"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Move True To iBCrlf
    Get ComAppendLine Of hoSb "-----BEGIN ENCRYPTED PRIVATE KEY-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MIGtMEkGCSqGSIb3DQEFDTA8MBsGCSqGSIb3DQEFDDAOBAiweNs9xIWNoAICCAAw" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "HQYJYIZIAWUDBAECBBCz0IMryNxuJEo5ChMktg9cBGCsKDEeRqGJX4g/X2c6CNtK" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "I8q7KClUwy9ms7ckHZAw/997WuW9QIGGnJEfHL/jSJsZViDwFAB4sunmdHSOTGMD" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "3ZINNlkA+XobMaQtj1HNERtb1qskW1mf/X0sauw5aPA=" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "-----END ENCRYPTED PRIVATE KEY-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "-----BEGIN CERTIFICATE-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MIICzjCCAlOgAwIBAgIETULS8zAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJVUzEW" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MBQGA1UEChMNRW50cnVzdCwgSW5jLjEfMB0GA1UECxMWRm9yIFRlc3QgUHVycG9z" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "ZXMgT25seTElMCMGA1UEAxMcRW50cnVzdCBFQ0MgRGVtb25zdHJhdGlvbiBDQTAe" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "Fw0xNjAzMTgxMjM5MzFaFw0xNjA1MTcxMzA5MzFaMFgxHzAdBgNVBAsTFkZvciBU" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "ZXN0IFB1cnBvc2VzIE9ubHkxHTAbBgNVBAsTFFBlcnNvbmEgTm90IFZlcmlmaWVk" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MRYwFAYDVQQDEw1DaGlsa2F0IEFkbWluMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "uB62JGMJKXnp1PNsOOIYKGhrzfLev3O+UuthL6UzEqNNDTd8dEYMUQP/DTS3qk98" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK/F4pF2Q995hr" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "o4HYMIHVMA4GA1UdDwEB/wQEAwIDiDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYB" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "BQUHAwQwNwYDVR0fBDAwLjAsoCqgKIYmaHR0cDovL2NybC5lbnRydXN0LmNvbS9D" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "UkwvZWNjZGVtby5jcmwwIAYDVR0RBBkwF4EVYWRtaW5AY2hpbGthdHNvZnQuY29t" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MB8GA1UdIwQYMBaAFCQFS+Fkghr4Ccz7eHkh+nDmkzLqMB0GA1UdDgQWBBTB82fm" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "vrdG2iX5uS/agVW3L4DisjAJBgNVHRMEAjAAMAoGCCqGSM49BAMDA2kAMGYCMQCH" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "ILghMprWoYPEp9mCE+tpVE7vYwkFV3m0RDzT2BSUezL8Ky78XNk+XPqSB2biT70C" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MQDCase1oaPY4AxCmjB+rEB1ir+QS8mrtF+iCSqHVv1aIxT6abQL57BZSdvwIm/T" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "T8o=" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "-----END CERTIFICATE-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "-----BEGIN CERTIFICATE-----" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MIICljCCAhugAwIBAgIETUHhezAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJVUzEW" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MBQGA1UEChMNRW50cnVzdCwgSW5jLjEfMB0GA1UECxMWRm9yIFRlc3QgUHVycG9z" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "ZXMgT25seTElMCMGA1UEAxMcRW50cnVzdCBFQ0MgRGVtb25zdHJhdGlvbiBDQTAe" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "Fw0xMTAxMjcyMDQ5NTRaFw0zNjAxMjcyMTE5NTRaMG0xCzAJBgNVBAYTAlVTMRYw" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "FAYDVQQKEw1FbnRydXN0LCBJbmMuMR8wHQYDVQQLExZGb3IgVGVzdCBQdXJwb3Nl" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "cyBPbmx5MSUwIwYDVQQDExxFbnRydXN0IEVDQyBEZW1vbnN0cmF0aW9uIENBMHYw" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "EAYHKoZIzj0CAQYFK4EEACIDYgAEhCWBpuJuzvRtQyibkcbCj7EkcwAqS2EqRQ/Q" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "ntroTdRM2SssEN4TruTxtwcY/7lR64L6Tfjz3+ujrfjNFss3EWVpUlbOJ+xHC3xH" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "PteNyAGZtHbZO3tVuhP6yX6dFqCCo4GLMIGIMCsGA1UdEAQkMCKADzIwMTEwMTI3" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "MjA0OTU0WoEPMjAzNjAxMjcyMTE5NTRaMAsGA1UdDwQEAwIBBjAfBgNVHSMEGDAW" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "gBQkBUvhZIIa+AnM+3h5Ifpw5pMy6jAdBgNVHQ4EFgQUJAVL4WSCGvgJzPt4eSH6" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "cOaTMuowDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAyAhA70OIb6lb" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "fN6kOTQloHyCLmihNK+PT5wOuaMR//KSQP2c/H18YhDYnlwMxF9fAjEA0URaJOXM" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "F0qwdvS2rm7N5PWMLc/4BbeOZyZ94XJiG5u96iTgp6N9JI0MMmCQE87N" iBCrlf To iSuccess
    Get ComAppendLine Of hoSb "-----END CERTIFICATE-----" iBCrlf To iSuccess

    Get Create (RefClass(cComChilkatPem)) To hoPem
    If (Not(IsComObjectCreated(hoPem))) Begin
        Send CreateComObject of hoPem
    End
    Get ComGetAsString Of hoSb To sTemp1
    Get ComLoadPem Of hoPem sTemp1 "secret123" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPem To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the private key and examine it in JSON Web Key form (JWK)
    Get ComGetPrivateKey Of hoPem 0 To vPrivKey
    If (IsComObject(vPrivKey)) Begin
        Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
        Set pvComObject Of hoPrivKey To vPrivKey
    End
    Get ComLastMethodSuccess Of hoPem To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoPem To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComGetJwk Of hoPrivKey To sTemp1
    Get ComLoad Of hoJson sTemp1 To iSuccess
    Set ComEmitCompact Of hoJson To False
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    Send Destroy of hoPrivKey

    // JWK output:

    // 	{ 
    // 	  "kty": "EC",
    // 	  "crv": "P-384",
    // 	  "x": "uB62JGMJKXnp1PNsOOIYKGhrzfLev3O-UuthL6UzEqNNDTd8dEYMUQP_DTS3qk98",
    // 	  "y": "gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK_F4pF2Q995hr",
    // 	  "d": "ugTy2ZpuQqv1uQyLSgz1SPRvngzrd5vLyzU2ICaJd25zZRIxxlNR-uFo9UWC6llt"
    // 	}

    // Now get 1st certificate and examine in XML format:
    Get ComGetCert Of hoPem 0 To vCert
    If (IsComObject(vCert)) Begin
        Get Create (RefClass(cComChilkatCert)) To hoCert
        Set pvComObject Of hoCert To vCert
    End
    Get ComLastMethodSuccess Of hoPem To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoPem To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComExportCertXml Of hoCert To sCertXml
    Send Destroy of hoCert

    Showln sCertXml

    // XML output:

    // <?xml version="1.0" encoding="utf-8" ?>
    // <sequence>
    //     <sequence>
    //         <contextSpecific tag="0" constructed="1">
    //             <int>02</int>
    //         </contextSpecific>
    //         <int>4D42D2F3</int>
    //         <sequence>
    //             <oid>1.2.840.10045.4.3.3</oid>
    //         </sequence>
    //         <sequence>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.6</oid>
    //                     <printable>US</printable>
    //                 </sequence>
    //             </set>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.10</oid>
    //                     <printable>Entrust, Inc.</printable>
    //                 </sequence>
    //             </set>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.11</oid>
    //                     <printable>For Test Purposes Only</printable>
    //                 </sequence>
    //             </set>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.3</oid>
    //                     <printable>Entrust ECC Demonstration CA</printable>
    //                 </sequence>
    //             </set>
    //         </sequence>
    //         <sequence>
    //             <utctime>160318123931Z</utctime>
    //             <utctime>160517130931Z</utctime>
    //         </sequence>
    //         <sequence>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.11</oid>
    //                     <printable>For Test Purposes Only</printable>
    //                 </sequence>
    //             </set>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.11</oid>
    //                     <printable>Persona Not Verified</printable>
    //                 </sequence>
    //             </set>
    //             <set>
    //                 <sequence>
    //                     <oid>2.5.4.3</oid>
    //                     <printable>Chilkat Admin</printable>
    //                 </sequence>
    //             </set>
    //         </sequence>
    //         <sequence>
    //             <sequence>
    //                 <oid>1.2.840.10045.2.1</oid>
    //                 <oid>1.3.132.0.34</oid>
    //             </sequence>
    //             <bits n="776">04B81EB62463092979E9D4F36C38E21828686BCDF2DEBF73BE52EB612FA53312A34D0D377C74460C5103FF0D34B7AA4F7C832404171766654B0F1747C5A24919675715EB3ED00F732C3EF4A3AC1CC1D06501DEBF022E70CAFC5E2917643DF7986B</bits>
    //         </sequence>
    //         <contextSpecific tag="3" constructed="1">
    //             <sequence>
    //                 <sequence>
    //                     <oid>2.5.29.15</oid>
    //                     <bool>1</bool>
    //                     <octets>AwIDiA==</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.37</oid>
    //                     <octets>MBQGCCsGAQUFBwMCBggrBgEFBQcDBA==</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.31</oid>
    //                     <octets>MC4wLKAqoCiGJmh0dHA6Ly9jcmwuZW50cnVzdC5jb20vQ1JML2VjY2RlbW8uY3Js</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.17</oid>
    //                     <octets>MBeBFWFkbWluQGNoaWxrYXRzb2Z0LmNvbQ==</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.35</oid>
    //                     <octets>MBaAFCQFS+Fkghr4Ccz7eHkh+nDmkzLq</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.14</oid>
    //                     <octets>BBTB82fmvrdG2iX5uS/agVW3L4Disg==</octets>
    //                 </sequence>
    //                 <sequence>
    //                     <oid>2.5.29.19</oid>
    //                     <octets>MAA=</octets>
    //                 </sequence>
    //             </sequence>
    //         </contextSpecific>
    //     </sequence>
    //     <sequence>
    //         <oid>1.2.840.10045.4.3.3</oid>
    //     </sequence>
    //     <bits n="832">30660231008720B821329AD6A183C4A7D98213EB69544EEF6309055779B4443CD3D814947B32FC2B2EFC5CD93E5CFA920766E24FBD023100C26AC7B5A1A3D8E00C429A307EAC40758ABF904BC9ABB45FA2092A8756FD5A2314FA69B40BE7B05949DBF0226FD34FCA</bits>
    // </sequence>
    // 
    // 
    // 


End_Procedure

 

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