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
(Xojo Plugin) 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.
// Note: This example requires Chilkat v9.5.0.66 or later. Dim success As Boolean // First build a JWK sample to load.. Dim json As New Chilkat.JsonObject success = json.UpdateString("kty","RSA") success = json.UpdateString("n","33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA04DDnEFGAf-kDQiNSe2ZtqC7bnIc8-KSG_qOGQIVaay4Ucr6ovDkykO5Hxn7OU7sJp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwFwnxCsU5-UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUEf0YN3_Q0auBkdbDR_ES2PbgKTJdkjc_rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1WSw") success = json.UpdateString("e","AQAB") success = json.UpdateString("d","DjU54mYvHpICXHjc5-JiFqiH8NkUgOG8LL4kwt3DeBp9bP0-5hSJH8vmzwJkeGG9L79EWG4b_bfxgYdeNX7cFFagmWPRFrlxbd64VRYFawZHRJt-2cbzMVI6DL8EK4bu5Ux5qTiV44Jw19hoD9nDzCTfPzSTSGrKD3iLPdnREYaIGDVxcjBv3Tx6rrv3Z2lhHHKhEHb0RRjATcjAVKV9NZhMajJ4l9pqJ3A4IQrCBl95ux6Xm1oXP0i6aR78cjchsCpcMXdP3WMsvHgTlsZT0RZLFHrvkiNHlPiil4G2_eHkwvT__CrcbO6SmI_zCtMmypuHJqcr-Xb7GPJoa64WoQ") success = json.UpdateString("p","8K33pX90XX6PZGiv26wZm7tfvqlqWFT03nUMvOAytqdxhO2HysiPn4W58OaJd1tY4372Qpiv6enmUeI4MidCie-s-d0_B6A0xfhU5EeeaDN0xDOOl8yN-kaaVj9b4HDR3c91OAwKpDJQIeJVZtxoijxl-SRx3u7Vs_7meeSpOfE") success = json.UpdateString("q","7a5KnUs1pTo72A-JquJvIz4Eu794Yh3ftTk_Et-83aE_FVc6Nk-EhfnwYSNpVmM6UKdrAoy5gsCvZPxrq-eR9pEwU8M5UOlki03vWY_nqDBpJSIqwPvGHUB16zvggsPQUyQBfnN3N8XlDi12n88ltvWwEhn1LQOwMUALEfka9_s") success = json.UpdateString("dp","DB9nGuHplY_7Xv5a5UCs5YgxkWPtJFfbIZ1Zr-XHCCY09JIWReOGQG226OhjwixKtOK_OqmAKtMKM9OmKviJRHNbDhbTxumN3u7cL8dftjXpSryiEQlPmWyW94MneI2WNIrvh4wruQuDt8EztgOiDFxwcnUgey8iend7WmZnE7E") success = json.UpdateString("dq","O-bSTUQ4N_UuQezgkF3TDrnBraO67leDGwRbfiE_U0ghQvqh5DA0QSPVzlWDZc9KUitvj8vxsR9o1PW9GS0an17GJEYuetLnkShKK3NWOhBBX6d1yP9rVdH6JhgIJEy_g0Suz7TAFiFc8i7JF8u4QJ05C8bZAMhOLotqftQeVOM") success = json.UpdateString("qi","InfGmkb2jNkPGuNiZ-mU0-ZrOgLza_fLL9ErZ35jUPhGFzdGxJNobklvsNoTd-E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO-sUV7zfFukexIcANmsd_oBBGKRoYzP5Tti4") // The JSON contains the following: // { // "kty": "RSA", // "n": "33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWb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9OmKviJRHNbDhbTxumN3u7cL8dftjXpSryiEQlPmWyW94MneI2WNIrvh4wruQuDt8EztgOiDFxwcnUgey8iend7WmZnE7E", // "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.EmitCompact = False // Show the JWK string to be loaded: Dim jwkStr As String jwkStr = json.Emit() Dim privKey As New Chilkat.PrivateKey success = privKey.LoadJwk(jwkStr) If (success <> True) Then System.DebugLog(privKey.LastErrorText) Return End If // 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.. System.DebugLog(privKey.GetXml()) // XML output: // <RSAKeyValue> // <Modulus>33TqqLR3eeUmDtHS89qF3p4MP7Wfqt2Zjj3lZjLjjCGDvwr9cJNlNDiuKboODgUiT4ZdPWbOiMAfDcDzlOxA04DDnEFGAf+kDQiNSe2ZtqC7bnIc8+KSG/qOGQIVaay4Ucr6ovDkykO5Hxn7OU7sJp9TP9H0JH8zMQA6YzijYH9LsupTerrY3U6zyihVEDXXOv08vBHk50BMFJbE9iwFwnxCsU5+UZUZYw87Uu0n4LPFS9BT8tUIvAfnRXIEWCha3KbFWmdZQZlyrFw0buUEf0YN3/Q0auBkdbDR/ES2PbgKTJdkjc/rEeM0TxvOUf7HuUNOhrtAVEN1D5uuxE1WSw==</Modulus> // <Exponent>AQAB</Exponent>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>InfGmkb2jNkPGuNiZ+mU0+ZrOgLza/fLL9ErZ35jUPhGFzdGxJNobklvsNoTd+E2GAU41YkJh24bncMLvJVYxHHA5iF7FBWx1SvpEyKVhhnIcuXGD7N5PbNZzEdmr9C6I7cPVkWO+sUV7zfFukexIcANmsd/oBBGKRoYzP5Tti4=</InverseQ> // </RSAKeyValue> System.DebugLog(privKey.GetPkcs8EncryptedPem("secret")) // 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/pe9vk84DAeQw0nxRbatxBqw2Zq0r6kjmwljRKNlJXGuPlfw0ooOH8F4c+E // e8XwrPKsOe14u4plP5H0u5N+JVBJGJdGQOuFGKU7Flw0hgEdwdyxHv5dDmPyhtyR // Ty1YjYyGQZxWLxw4Q2qJwpikL6o8ylXegSr20aeHFDvtCY63UFLxvZ4pDnCxOIR8 // xXJJy179t6BbCPQao4c5U/PRsahgUn/XjKL0lXFUyWoX6Rehr8Zmr+RZFaVhG4WO // ZodH2CzYNv6co7bfLKLa9u1NHPfTVTVxZTYKw/tuPGscVVhXptPDCjHqOvCtX+pS // +oshZ1SwM/0MgDmJfyJ0rDkkjBDsv5x5iJV9jmx/DAlGhOR7Is9xgjx5XEXD8oug // fVQI2ZpZqQ1EAPCGKfQl7XUMwN4S0cmYf/xS5afNMyABJGj0wUdF3YlHxkz+wkeE // poQ/1EVQLCTVcJBrbbpkJAgUFFwOm6o8behxgVr3yHuO6zuFi5rXVqnztm9JYMRj // H3ACb14wRR2ctyZovPvZpODywH1K7kfIdRn9UE/o21HfnhtdUJEFPTS16mjGsJpx // E5aSCXVrvrb/JqHpSvNRpKlHWV9nxuONzqBX3QKa5X/31opPI7qEBYND0oHuH/cB // BYlstKCUhb4hmg4M6qwA7qC5aLJVoz8toWA4cv0JhhVqnR1jcsyq+r4zusdiEJ2I // kW5F9u0zNLa8xHByz3Qr6wTMBu3NY3w9NFwIXXq2lkrxDlvHFjMImdXFzb/G1fbc // 7BDIOwPrEffb0yEsgHxJVHE3NPZJOrbLquS7M8IFjhoky6QxesaU/QLjyMMKphrQ // EdmBRwKsYHS9BdX4YawtCRjJd3n+z2guF+dIHDvIZVgL1Ednu7G654gVl+MJVIHo // Wc7pGOc3PRaAEPRF9O0Smwwr+x1qRedoCVhLc3idWPAW+dOTpZUbTSB21D/Q8vdr // QJ0fNbTa4AGLLoMOp0rZI1ji6ghcMqz5FqyhDqawSV7je6Z/EE0DRwzRZ1mRwykF // Qe0= // -----END ENCRYPTED PRIVATE KEY----- |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.