(Unicode C++) Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
How to output the public part of a private key:
Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem
#include <CkPrivateKeyW.h>
#include <CkPublicKeyW.h>
void ChilkatSample(void)
{
CkPrivateKeyW pkey;
// Load the private key from an PEM file:
bool success = pkey.LoadPemFile(L"private.pem");
if (success != true) {
wprintf(L"%s\n",pkey.lastErrorText());
return;
}
CkPublicKeyW *pubKey = pkey.GetPublicKey();
if (pkey.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",pkey.lastErrorText());
return;
}
success = pubKey->SavePemFile(false,L"pubKey.pem");
if (success != true) {
wprintf(L"%s\n",pubKey->lastErrorText());
delete pubKey;
return;
}
wprintf(L"Success.\n");
delete pubKey;
}
|