(C++) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64. Note: This example requires Chilkat v11.0.0 or greater.
#include <CkPublicKey.h>
#include <CkRsa.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkPublicKey pubkey;
success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==");
if (success == false) {
std::cout << pubkey.lastErrorText() << "\r\n";
return;
}
CkRsa rsa;
success = rsa.UsePublicKey(pubkey);
if (success == false) {
std::cout << rsa.lastErrorText() << "\r\n";
return;
}
rsa.put_EncodingMode("base64");
const char *encryptedStr = rsa.encryptStringENC("12345678",false);
std::cout << encryptedStr << "\r\n";
}
|