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 PEM Public/Private Key into RSA ObjectDemonstrates how to load a PEM key into the Chilkat RSA object.
#include <CkRsa.h> #include <CkPublicKey.h> #include <CkPrivateKey.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkRsa rsa; // First demonstrate importing a PEM public key: const char *publicKeyPem = "PEM public-key data goes here"; CkPublicKey pubkey; bool success = pubkey.LoadOpenSslPem(publicKeyPem); if (success != true) { strOut.append(pubkey.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } const char *publicKeyXml = pubkey.getXml(); success = rsa.ImportPublicKey(publicKeyXml); if (success != true) { strOut.append(rsa.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Demonstrate importing a PEM private key: const char *privateKeyPem = "PEM private-key data goes here"; CkPrivateKey privkey; // If the private key PEM is protected with a password, then // call LoadEncryptedPem. Otherwise call LoadPem. success = privkey.LoadPem(privateKeyPem); if (success != true) { strOut.append(privkey.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } const char *privateKeyXml = privkey.getXml(); success = rsa.ImportPrivateKey(privateKeyXml); if (success != true) { strOut.append(rsa.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("OK!"); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.