本文整理汇总了C++中rsa::PrivateKey::GenerateRandomWithKeySize方法的典型用法代码示例。如果您正苦于以下问题:C++ PrivateKey::GenerateRandomWithKeySize方法的具体用法?C++ PrivateKey::GenerateRandomWithKeySize怎么用?C++ PrivateKey::GenerateRandomWithKeySize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa::PrivateKey
的用法示例。
在下文中一共展示了PrivateKey::GenerateRandomWithKeySize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: rand
CppRsaPublicKeyImpl::CppRsaPublicKeyImpl(const QByteArray &data, bool seed) :
m_public_key(new RSA::PublicKey())
{
if(seed) {
RSA::PrivateKey key;
CryptoRandom rand(data);
key.GenerateRandomWithKeySize(GetCppRandom(rand),
RsaPrivateKey::DefaultKeySize());
m_public_key.reset(new RSA::PublicKey(key));
} else {
ByteQueue queue;
queue.Put2(reinterpret_cast<const byte *>(data.data()), data.size(), 0, true);
try {
m_public_key->Load(queue);
} catch (std::exception &e) {
qWarning() << "In CppRsaPublicKey: " << e.what();
m_valid = false;
return;
}
}
m_valid = true;
}