err = PGPsdkInit();
err = PGPNewContext( kPGPsdkAPIVersion, &context );
const void *nameKey = "nameKey";
PGPOptionListRef m_optsEncode = NULL;
PGPKeySetRef keySet = kInvalidPGPKeySetRef;
err = PGPNewKeySet (context, &keySet);
err = PGPBuildOptionList ( context,
&m_optsEncode,
PGPOKeyGenParams (context, kPGPPublicKeyAlgorithm_RSA, 2048),
PGPOKeyGenName (context, nameKey, 255),
PGPOLastOption( context ) );
PGPGlobalRandomPoolAddSystemState();
PGPUInt32 currEntropyAmt = PGPGlobalRandomPoolGetEntropy();
PGPUInt32 entropyNeeded = PGPGetKeyEntropyNeeded(context,
PGPOKeyGenParams(context,kPGPPublicKeyAlgorithm_RSA,2048),
PGPOLastOption(context)
);
PGPUInt32 val;
while (currEntropyAmt < entropyNeeded)
{
val = PGPGlobalRandomPoolMouseMoved();
currEntropyAmt = PGPGlobalRandomPoolGetEntropy();
}
const char *PassPhrase = "";
PGPKeyRef newKey;
err = PGPGenerateKey (context, &newKey,
PGPOKeySetRef (context, keySet),
m_optsEncode,
PGPOPassphrase (context, PassPhrase),
PGPOExpiration (context, kPGPExpirationTime_Never),
PGPOLastOption( context ));
if( IsPGPError( err ) ) {
char errString[256];
PGPGetErrorString( err, sizeof( errString), errString );
std::ofstream outFile ("err.dat", std::ios::app);
outFile << "PGPGenerateKey " << errString << std::endl;
outFile.close ();
};