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) 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.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoJson String sJwkStr Handle hoPubKey Boolean iBPreferPkcs1 String sTemp1 // Note: This example requires Chilkat v9.5.0.66 or later. // First build a JWK sample to load.. Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "kty" "EC" To iSuccess Get ComUpdateString Of hoJson "crv" "P-256" To iSuccess Get ComUpdateString Of hoJson "x" "oBUyo8CQAFPeYPvv78ylh5MwFZjTCLQeb042TjiMJxE" To iSuccess Get ComUpdateString Of hoJson "y" "vvQyxZkUjJQUPU_0bCy3Pj5qQdfu8jwEfqEeYGZ95CU" To iSuccess // 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. Set ComEmitCompact Of hoJson To False // Show the JWK string to be loaded: Get ComEmit Of hoJson To sJwkStr Get Create (RefClass(cComChilkatPublicKey)) To hoPubKey If (Not(IsComObjectCreated(hoPubKey))) Begin Send CreateComObject of hoPubKey End // The LoadFromString method will automatically detect the format. Get ComLoadFromString Of hoPubKey sJwkStr To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoPubKey To sTemp1 Showln sTemp1 Procedure_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.. Get ComGetXml Of hoPubKey To sTemp1 Showln sTemp1 // 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.. Move False To iBPreferPkcs1 Get ComGetPem Of hoPubKey iBPreferPkcs1 To sTemp1 Showln sTemp1 // PEM output // -----BEGIN PUBLIC KEY----- // MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA // AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA//// // ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd // NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5 // RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA // //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABKAVMqPAkABT3mD77+/MpYeT // MBWY0wi0Hm9ONk44jCcRvvQyxZkUjJQUPU/0bCy3Pj5qQdfu8jwEfqEeYGZ95CU= // -----END PUBLIC KEY----- End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.