Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Load RSA Private Key from JWK Format (JSON Web Key)Demonstrates how to load an RSA private key from JWK (JSON Web Key) format. Note: This example requires Chilkat v9.5.0.66 or later.
#include <CkJsonObject.h> #include <CkPrivateKey.h> void ChilkatSample(void) { CkString strOut; // Note: This example requires Chilkat v9.5.0.66 or later. bool success; // First build a JWK sample to load.. CkJsonObject json; json.UpdateString("kty","RSA"); json.UpdateString("n","33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA04DDnEFGAf-kDQiNSe2ZtqC7bnIc8-KSG_qOGQIVaay4Ucr6ovDkykO5Hxn7OU7sJp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwFwnxCsU5-UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUEf0YN3_Q0auBkdbDR_ES2PbgKTJdkjc_rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1WSw"); json.UpdateString("e","AQAB"); json.UpdateString("d","DjU54mYvHpICXHjc5-JiFqiH8NkUgOG8LL4kwt3DeBp9bP0-5hSJH8vmzwJkeGG9L79EWG4b_bfxgYdeNX7cFFagmWPRFrlxbd64VRYFawZHRJt-2cbzMVI6DL8EK4bu5Ux5qTiV44Jw19hoD9nDzCTfPzSTSGrKD3iLPdnREYaIGDVxcjBv3Tx6rrv3Z2lhHHKhEHb0RRjATcjAVKV9NZhMajJ4l9pqJ3A4IQrCBl95ux6Xm1oXP0i6aR78cjchsCpcMXdP3WMsvHgTlsZT0RZLFHrvkiNHlPiil4G2_eHkwvT__CrcbO6SmI_zCtMmypuHJqcr-Xb7GPJoa64WoQ"); json.UpdateString("p","8K33pX90XX6PZGiv26wZm7tfvqlqWFT03nUMvOAytqdxhO2HysiPn4W58OaJd1tY4372Qpiv6enmUeI4MidCie-s-d0_B6A0xfhU5EeeaDN0xDOOl8yN-kaaVj9b4HDR3c91OAwKpDJQIeJVZtxoijxl-SRx3u7Vs_7meeSpOfE"); json.UpdateString("q","7a5KnUs1pTo72A-JquJvIz4Eu794Yh3ftTk_Et-83aE_FVc6Nk-EhfnwYSNpVmM6UKdrAoy5gsCvZPxrq-eR9pEwU8M5UOlki03vWY_nqDBpJSIqwPvGHUB16zvggsPQUyQBfnN3N8XlDi12n88ltvWwEhn1LQOwMUALEfka9_s"); json.UpdateString("dp","DB9nGuHplY_7Xv5a5UCs5YgxkWPtJFfbIZ1Zr-XHCCY09JIWReOGQG226OhjwixKtOK_OqmAKtMKM9OmKviJRHNbDhbTxumN3u7cL8dftjXpSryiEQlPmWyW94MneI2WNIrvh4wruQuDt8EztgOiDFxwcnUgey8iend7WmZnE7E"); json.UpdateString("dq","O-bSTUQ4N_UuQezgkF3TDrnBraO67leDGwRbfiE_U0ghQvqh5DA0QSPVzlWDZc9KUitvj8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy_g0Suz7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOM"); json.UpdateString("qi","InfGmkb2jNkPGuNiZ-mU0-ZrOgLza_fLL9ErZ35jUPhGFzdGxJNobklvsNoTd-E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO-sUV7zfFukexIcANmsd_oBBGKRoYzP5Tti4"); // The JSON contains the following: // { // "kty": "RSA", // "n": "33TqqLR3eeUmDtHS89qF3p4MP7Wf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bIZ1Zr-XHCCY09JIWReOGQG226OhjwixKtOK_OqmAKtMKM9OmKviJRHNbDhbTxumN3u7cL8dftjXpSryiEQlPmWyW94MneI2WNIrvh4wruQuDt8EztgOiDFxwcnUgey8iend7WmZnE7E", // "dq": "O-bSTUQ4N_UuQezgkF3TDrnBraO67leDGwRbfiE_U0ghQvqh5DA0QSPVzlWDZc9KUitvj8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy_g0Suz7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOM", // "qi": "InfGmkb2jNkPGuNiZ-mU0-ZrOgLza_fLL9ErZ35jUPhGFzdGxJNobklvsNoTd-E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO-sUV7zfFukexIcANmsd_oBBGKRoYzP5Tti4" // } // Note: The JSON can contain other members, such as "use", "kid", or anything else. These will be ignored. json.put_EmitCompact(false); // Show the JWK string to be loaded: const char *jwkStr = json.emit(); CkPrivateKey privKey; success = privKey.LoadJwk(jwkStr); if (success != true) { strOut.append(privKey.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // 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.. strOut.append(privKey.getXml()); strOut.append("\r\n"); // XML output: // <RSAKeyValue> // <Modulus>33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA04DDnEFGAf+kDQiNSe2ZtqC7bnIc8+KSG/qOGQIVaay4Ucr6ovDkykO5Hxn7OU7sJp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwFwnxCsU5+UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUEf0YN3/Q0auBk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WOhBBX6d1yP9rVdH6JhgIJEy/g0Suz7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOM=</DQ> // <InverseQ>InfGmkb2jNkPGuNiZ+mU0+ZrOgLza/fLL9ErZ35jUPhGFzdGxJNobklvsNoTd+E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO+sUV7zfFukexIcANmsd/oBBGKRoYzP5Tti4=</InverseQ> // </RSAKeyValue> strOut.append(privKey.getPkcs8EncryptedPem("secret")); strOut.append("\r\n"); // PEM output // -----BEGIN ENCRYPTED PRIVATE KEY----- // MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIRp9eD6gS5x4CAggA // MBQGCCqGSIb3DQMHBAgMYSDcTKD+UASCBMgAtoYFncjSiep51R2qhK0j5RLsPdCD // tb3GiwJJycYkMMpbOCVIBNtDMDRrAuTQmdDjFAgKkfktT0p1fLd0RHAv4JKWrDeE // OsV1BS1pJgI6ulEJVs7nwV9y6JkzuqIiguVM1ukYm8uwjVwKBQtOg9jZjE7uLqSs // X508rEI3BNxKeD5VMpIDzh+nil5pG3AC74/yAJFJop5J+dcoYgTIVwwcWsieKpCD // wgTmXQ53tYGtudC4HM3Wtp2PHdg6jDVZFeXkjbcJFKsmalw9wCDOUvE64onUqyhf // z/8Thu2g3Bs4rYXflEbIbsxqYit7wM5nLAvqByKdOUdmOLLsj0PlnN+ZA9+JRmnI // bOHUg+XxvreRdphXeNeUF16ro22c9TMyjSXiEP6RvrEcyoi0UnVeeCKjO90q10n3 // TQdIFMkY1gwgUuBo+OUtZPTkbrFA33e9NiHc/OiHVETDHYO/WEceu2ef6mSjcw+C // Q6WMR6EH24eXUfoI4xaNexGaR7w2EkU1UfGqs6f+c4siZMPExm41H2Xc/MBOpmES // iQxoinajiiw4DOQ08Cs/hVAm4/dH9XhCnBIig+PZpmeOZGoeyK2D57czLaTPBHdH // Jr7sZ/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EY----- SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.