(C) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private key. Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkBinData.h>
#include <C_CkPrivateKey.h>
#include <C_CkPublicKey.h>
void ChilkatSample(void)
{
BOOL success;
HCkBinData bd;
HCkPrivateKey privKey;
HCkPublicKey pubKey;
const char *pubKeyBase64;
success = FALSE;
// Load a private key from base64.
bd = CkBinData_Create();
success = CkBinData_AppendEncoded(bd,"MHQCA....n0Q==","base64");
privKey = CkPrivateKey_Create();
success = CkPrivateKey_LoadAnyFormat(privKey,bd,"");
if (success == FALSE) {
printf("%s\n",CkPrivateKey_lastErrorText(privKey));
CkBinData_Dispose(bd);
CkPrivateKey_Dispose(privKey);
return;
}
pubKey = CkPublicKey_Create();
CkPrivateKey_ToPublicKey(privKey,pubKey);
pubKeyBase64 = CkPublicKey_getEncoded(pubKey,TRUE,"base64");
printf("%s\n",pubKeyBase64);
CkBinData_Dispose(bd);
CkPrivateKey_Dispose(privKey);
CkPublicKey_Dispose(pubKey);
}
|