Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Convert PFX to JWK SetDemonstrates how to convert a PFX (.pfx or .p12) to a JWK Set (a JSON Web Key Set). This example requires Chilkat v9.5.0.66 or greater.
Use ChilkatAx-win32.pkg Procedure Test Handle hoPfx Boolean iSuccess String sAlias String sPassword Variant vJks Handle hoJks Variant vSbJwkSet Handle hoSbJwkSet Handle hoJwkSet String sTemp1 Boolean bTemp1 // IMPORTANT: This example requires Chilkat v9.5.0.66 or greater. // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatPfx)) To hoPfx If (Not(IsComObjectCreated(hoPfx))) Begin Send CreateComObject of hoPfx End Get ComLoadPfxFile Of hoPfx "qa_data/pfx/myEccCert.p12" "MY_ECC_PFX_PASSWORD" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End // To get the contents of the PFX in JWK Set form, we must first convert // to a Java KeyStore object: // The alias will become the key id ("kid") the the JWK Set. // The password is an input argument that becomes the password for the JavaKeyStore. Move "my_ecc_key" To sAlias Move "secret123" To sPassword Get ComToJavaKeyStore Of hoPfx sAlias sPassword To vJks If (IsComObject(vJks)) Begin Get Create (RefClass(cComChilkatJavaKeyStore)) To hoJks Set pvComObject Of hoJks To vJks End Get ComLastMethodSuccess Of hoPfx To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJwkSet If (Not(IsComObjectCreated(hoSbJwkSet))) Begin Send CreateComObject of hoSbJwkSet End // The ToJwkSet method writes to sbJwkSet. Get pvComObject of hoSbJwkSet to vSbJwkSet Get ComToJwkSet Of hoJks sPassword vSbJwkSet To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoJks To sTemp1 Showln sTemp1 Send Destroy of hoJks Procedure_Return End Send Destroy of hoJks Get Create (RefClass(cComChilkatJsonObject)) To hoJwkSet If (Not(IsComObjectCreated(hoJwkSet))) Begin Send CreateComObject of hoJwkSet End Get pvComObject of hoSbJwkSet to vSbJwkSet Get ComLoadSb Of hoJwkSet vSbJwkSet To iSuccess Set ComEmitCompact Of hoJwkSet To False Get ComEmit Of hoJwkSet To sTemp1 Showln sTemp1 // The output is: // (Line breaks in the "x5c" base64 data were added for readability) // { // "keys": [ // { // "kty": "EC", // "crv": "P-384", // "x": "uB62JGMJKXnp1PNsOOIYKGhrzfLev3O-UuthL6UzEqNNDTd8dEYMUQP_DTS3qk98", // "y": "gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK_F4pF2Q995hr", // "d": "ugTy2ZpuQqv1uQyLSgz1SPRvngzrd5vLyzU2ICaJd25zZRIxxlNR-uFo9UWC6llt", // "kid": "my_ecc_key", // "x5c": [ // "MIICzjCCAlOgAwIBAgIETULS8zAKBggqhkjOPQQDAzBtMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNRW50 // cnVzdCwgSW5jLjEfMB0GA1UECxMWRm9yIFRlc3QgUHVycG9zZXMgT25seTElMCMGA1UEAxMcRW50cnVzdCBFQ0MgR // GVtb25zdHJhdGlvbiBDQTAeFw0xNjAzMTgxMjM5MzFaFw0xNjA1MTcxMzA5MzFaMFgxHzAdBgNVBAsTFkZvciBUZX // N0IFB1cnBvc2VzIE9ubHkxHTAbBgNVBAsTFFBlcnNvbmEgTm90IFZlcmlmaWVkMRYwFAYDVQQDEw1DaGlsa2F0IEF // kbWluMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEuB62JGMJKXnp1PNsOOIY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NFss3EWVpUlbOJ+xHC3xHPteNyAGZtHbZO // 3tVuhP6yX6dFqCCo4GLMIGIMCsGA1UdEAQkMCKADzIwMTEwMTI3MjA0OTU0WoEPMjAzNjAxMjcyMTE5NTRaMAsGA1 // UdDwQEAwIBBjAfBgNVHSMEGDAWgBQkBUvhZIIa+AnM+3h5Ifpw5pMy6jAdBgNVHQ4EFgQUJAVL4WSCGvgJzPt4eSH // 6cOaTMuowDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAyAhA70OIb6lbfN6kOTQloHyCLmihNK+PT5wO // uaMR//KSQP2c/H18YhDYnlwMxF9fAjEA0URaJOXMF0qwdvS2rm7N5PWMLc/4BbeOZyZ94XJiG5u96iTgp6N9JI0MM // mCQE87N" // ] // } // ] // } // End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.