本文整理汇总了C++中rsa::PrivateKey::Validate方法的典型用法代码示例。如果您正苦于以下问题:C++ PrivateKey::Validate方法的具体用法?C++ PrivateKey::Validate怎么用?C++ PrivateKey::Validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa::PrivateKey
的用法示例。
在下文中一共展示了PrivateKey::Validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DecodeFromFile
static bool DecodeFromFile(const char* filename, RSA::PrivateKey& key)
{
try {
ByteQueue queue;
FileSource file(filename, true);
file.TransferTo(queue);
queue.MessageEnd();
key.BERDecodePrivateKey(queue, false, queue.MaxRetrievable());
return key.Validate(rng, 3);
} catch (...) {
return false;
}
}
示例2: main
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
// http://www.cryptopp.com/docs/ref/class_auto_seeded_random_pool.html
AutoSeededRandomPool rnd;
try
{
// http://www.cryptopp.com/docs/ref/rsa_8h.html
RSA::PrivateKey rsaPrivate;
rsaPrivate.GenerateRandomWithKeySize(rnd, 1024);
RSA::PublicKey rsaPublic(rsaPrivate);
if(!rsaPrivate.Validate(rnd, 3)) {
throw runtime_error("Validation failed");
}
SavePrivateKey("rsa-private.key", rsaPrivate);
SavePublicKey("rsa-public.key", rsaPublic);
cout << "Successfully generated and saved RSA keys:" << endl;
cout << "Values:" << endl;
cout << "N: " << rsaPrivate.GetModulus() << endl;
cout << "E: " << rsaPrivate.GetPublicExponent() << endl;
cout << "D: " << rsaPrivate.GetPrivateExponent() << endl;
}
catch(CryptoPP::Exception& e)
{
cerr << e.what() << endl;
return -2;
}
catch(std::exception& e)
{
cerr << e.what() << endl;
return -1;
}
return 0;
}
示例3: GenerateRSAKey
/*
* generate the RSA public key and private key in separate file
*/
void MyRSA::GenerateRSAKey(unsigned int keyLength, const char *privFilename,
const char *pubFilename)
{ AutoSeededRandomPool rng;
RSA::PrivateKey priv;
priv.GenerateRandomWithKeySize(rng, 1024);
if (!priv.Validate(rng, 3))
{
throw("RSA key generation failed");
}
HexEncoder privFile(new FileSink(privFilename));
priv.DEREncode(privFile);
privFile.MessageEnd();
RSA::PublicKey pub;
pub.AssignFrom(priv);
HexEncoder pubFile(new FileSink(pubFilename));
pub.DEREncode(pubFile);
pubFile.MessageEnd();
}