(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 <CkPrivateKey.h>
#include <CkPublicKey.h>
void ChilkatSample(void)
{
CkPrivateKey pkey;
// Load the private key from an PEM file:
bool success = pkey.LoadPemFile("private.pem");
if (success != true) {
std::cout << pkey.lastErrorText() << "\r\n";
return;
}
CkPublicKey *pubKey = pkey.GetPublicKey();
if (pkey.get_LastMethodSuccess() == false) {
std::cout << pkey.lastErrorText() << "\r\n";
return;
}
success = pubKey->SavePemFile(false,"pubKey.pem");
if (success != true) {
std::cout << pubKey->lastErrorText() << "\r\n";
delete pubKey;
return;
}
std::cout << "Success." << "\r\n";
delete pubKey;
}
|