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
(Unicode C) Load PEM Public/Private Key into RSA ObjectDemonstrates how to load a PEM key into the Chilkat RSA object.
#include <C_CkRsaW.h> #include <C_CkPublicKeyW.h> #include <C_CkPrivateKeyW.h> void ChilkatSample(void) { HCkRsaW rsa; const wchar_t *publicKeyPem; HCkPublicKeyW pubkey; BOOL success; const wchar_t *publicKeyXml; const wchar_t *privateKeyPem; HCkPrivateKeyW privkey; const wchar_t *privateKeyXml; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rsa = CkRsaW_Create(); // First demonstrate importing a PEM public key: publicKeyPem = L"PEM public-key data goes here"; pubkey = CkPublicKeyW_Create(); success = CkPublicKeyW_LoadFromString(pubkey,publicKeyPem); if (success != TRUE) { wprintf(L"%s\n",CkPublicKeyW_lastErrorText(pubkey)); CkRsaW_Dispose(rsa); CkPublicKeyW_Dispose(pubkey); return; } publicKeyXml = CkPublicKeyW_getXml(pubkey); success = CkRsaW_ImportPublicKey(rsa,publicKeyXml); if (success != TRUE) { wprintf(L"%s\n",CkRsaW_lastErrorText(rsa)); CkRsaW_Dispose(rsa); CkPublicKeyW_Dispose(pubkey); return; } // Demonstrate importing a PEM private key: privateKeyPem = L"PEM private-key data goes here"; privkey = CkPrivateKeyW_Create(); // If the private key PEM is protected with a password, then // call LoadEncryptedPem. Otherwise call LoadPem. success = CkPrivateKeyW_LoadPem(privkey,privateKeyPem); if (success != TRUE) { wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privkey)); CkRsaW_Dispose(rsa); CkPublicKeyW_Dispose(pubkey); CkPrivateKeyW_Dispose(privkey); return; } privateKeyXml = CkPrivateKeyW_getXml(privkey); success = CkRsaW_ImportPrivateKey(rsa,privateKeyXml); if (success != TRUE) { wprintf(L"%s\n",CkRsaW_lastErrorText(rsa)); CkRsaW_Dispose(rsa); CkPublicKeyW_Dispose(pubkey); CkPrivateKeyW_Dispose(privkey); return; } wprintf(L"OK!\n"); CkRsaW_Dispose(rsa); CkPublicKeyW_Dispose(pubkey); CkPrivateKeyW_Dispose(privkey); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.