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
(C) Get RSA Private Key in JWK Format (JSON Web Key)Demonstrates how to get an RSA private key in JWK (JSON Web Key) format. Note: This example requires Chilkat v9.5.0.66 or later.
#include <C_CkStringBuilder.h> #include <C_CkPrivateKey.h> #include <C_CkJsonObject.h> void ChilkatSample(void) { HCkStringBuilder sbPem; BOOL success; HCkPrivateKey privKey; const char *jwk; HCkJsonObject json; // Note: This example requires Chilkat v9.5.0.66 or later. // Load a PEM file into memory. sbPem = CkStringBuilder_Create(); success = CkStringBuilder_LoadFile(sbPem,"qa_data/pem/rsa_passwd.pem","utf-8"); if (success != TRUE) { printf("Failed to load PEM file.\n"); CkStringBuilder_Dispose(sbPem); return; } // Load the PEM into a private key object. privKey = CkPrivateKey_Create(); success = CkPrivateKey_LoadEncryptedPem(privKey,CkStringBuilder_getAsString(sbPem),"passwd"); if (success != TRUE) { printf("%s\n",CkPrivateKey_lastErrorText(privKey)); CkStringBuilder_Dispose(sbPem); CkPrivateKey_Dispose(privKey); return; } // Get the private key in JWK format: jwk = CkPrivateKey_getJwk(privKey); // The GetJwk method will return the JWK in the most compact JSON format possible, // as a single line with no extra whitespace. To get a more human-readable JWK (for this example), // load into a Chilkat JSON object and emit non-compact: json = CkJsonObject_Create(); CkJsonObject_Load(json,jwk); CkJsonObject_putEmitCompact(json,FALSE); printf("RSA Private Key in JWK format:\n"); printf("%s\n",CkJsonObject_emit(json)); // Sample output: // { // "kty": "RSA", // "n": "33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA04DDn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3u7cL8dftjXpSryiEQlPmWyW94MneI2WNIrvh4wruQuDt8EztgOiDFxwcnUgey8iend7WmZnE7E", // "dq": "O-bSTUQ4N_UuQezgkF3TDrnBraO67leDGwRbfiE_U0ghQvqh5DA0QSPVzlWDZc9KUitvj8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy_g0Suz7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOM", // "qi": "InfGmkb2jNkPGuNiZ-mU0-ZrOgLza_fLL9ErZ35jUPhGFzdGxJNobklvsNoTd-E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO-sUV7zfFukexIcANmsd_oBBGKRoYzP5Tti4" // } CkStringBuilder_Dispose(sbPem); CkPrivateKey_Dispose(privKey); CkJsonObject_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.