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
(PureBasic) 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.
IncludeFile "CkStringBuilder.pb" IncludeFile "CkJavaKeyStore.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkPfx.pb" Procedure ChilkatExample() ; 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. pfx.i = CkPfx::ckCreate() If pfx.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkPfx::ckLoadPfxFile(pfx,"qa_data/pfx/myEccCert.p12","MY_ECC_PFX_PASSWORD") If success <> 1 Debug CkPfx::ckLastErrorText(pfx) CkPfx::ckDispose(pfx) ProcedureReturn EndIf ; 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. alias.s = "my_ecc_key" password.s = "secret123" jks.i = CkPfx::ckToJavaKeyStore(pfx,alias,password) If CkPfx::ckLastMethodSuccess(pfx) <> 1 Debug CkPfx::ckLastErrorText(pfx) CkPfx::ckDispose(pfx) ProcedureReturn EndIf sbJwkSet.i = CkStringBuilder::ckCreate() If sbJwkSet.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The ToJwkSet method writes to sbJwkSet. success = CkJavaKeyStore::ckToJwkSet(jks,password,sbJwkSet) If success <> 1 Debug CkJavaKeyStore::ckLastErrorText(jks) CkJavaKeyStore::ckDispose(jks) CkPfx::ckDispose(pfx) CkStringBuilder::ckDispose(sbJwkSet) ProcedureReturn EndIf CkJavaKeyStore::ckDispose(jks) jwkSet.i = CkJsonObject::ckCreate() If jwkSet.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jwkSet,sbJwkSet) CkJsonObject::setCkEmitCompact(jwkSet, 0) Debug CkJsonObject::ckEmit(jwkSet) ; 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 ; kbWluMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEuB62JGMJKXnp1PNsOOIYKGhrzfLev3O+UuthL6UzEqNNDTd8dEYM ; UQP/DTS3qk98gyQEFxdmZUsPF0fFokkZZ1cV6z7QD3MsPvSjrBzB0GUB3r8CLnDK/F4pF2Q995hro4HYMIHVMA4GA ; 1UdDwEB/wQEAwIDi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; UdDwQEAwIBBjAfBgNVHSMEGDAWgBQkBUvhZIIa+AnM+3h5Ifpw5pMy6jAdBgNVHQ4EFgQUJAVL4WSCGvgJzPt4eSH ; 6cOaTMuowDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAyAhA70OIb6lbfN6kOTQloHyCLmihNK+PT5wO ; uaMR//KSQP2c/H18YhDYnlwMxF9fAjEA0URaJOXMF0qwdvS2rm7N5PWMLc/4BbeOZyZ94XJiG5u96iTgp6N9JI0MM ; mCQE87N" ; ] ; } ; ] ; } ; CkPfx::ckDispose(pfx) CkStringBuilder::ckDispose(sbJwkSet) CkJsonObject::ckDispose(jwkSet) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.