(Unicode 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 <CkPublicKeyW.h>
#include <CkRsaW.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.
CkPublicKeyW pubkey;
success = pubkey.LoadBase64(L"MIICdgIBADA ... A9PXLk+j5A==");
if (success == false) {
wprintf(L"%s\n",pubkey.lastErrorText());
return;
}
CkRsaW rsa;
success = rsa.UsePublicKey(pubkey);
if (success == false) {
wprintf(L"%s\n",rsa.lastErrorText());
return;
}
rsa.put_EncodingMode(L"base64");
const wchar_t *encryptedStr = rsa.encryptStringENC(L"12345678",false);
wprintf(L"%s\n",encryptedStr);
}
|