(C) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used. Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkCert.h>
#include <C_CkPublicKey.h>
#include <C_CkRsa.h>
void ChilkatSample(void)
{
BOOL success;
HCkCert cert;
HCkPublicKey pubKey;
HCkRsa rsa;
const char *encryptedStr;
success = FALSE;
cert = CkCert_Create();
success = CkCert_LoadFromFile(cert,"qa_data/pem/mf_public_rsa.pem");
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkCert_Dispose(cert);
return;
}
pubKey = CkPublicKey_Create();
CkCert_GetPublicKey(cert,pubKey);
rsa = CkRsa_Create();
CkRsa_UsePublicKey(rsa,pubKey);
CkRsa_putEncodingMode(rsa,"base64");
encryptedStr = CkRsa_encryptStringENC(rsa,"hello",FALSE);
printf("encrypted string = %s\n",encryptedStr);
CkCert_Dispose(cert);
CkPublicKey_Dispose(pubKey);
CkRsa_Dispose(rsa);
}
|