C++
C++
RSA Import Public Key from Certificate PEM
See more RSA Examples
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.Chilkat C++ Downloads
#include <CkCert.h>
#include <CkPublicKey.h>
#include <CkRsa.h>
void ChilkatSample(void)
{
bool success = false;
CkCert cert;
success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem");
if (success == false) {
std::cout << cert.lastErrorText() << "\r\n";
return;
}
CkPublicKey pubKey;
cert.GetPublicKey(pubKey);
CkRsa rsa;
rsa.UsePublicKey(pubKey);
rsa.put_EncodingMode("base64");
const char *encryptedStr = rsa.encryptStringENC("hello",false);
std::cout << "encrypted string = " << encryptedStr << "\r\n";
}