本文整理汇总了C++中rsa::PrivateKey::GetModulus方法的典型用法代码示例。如果您正苦于以下问题:C++ PrivateKey::GetModulus方法的具体用法?C++ PrivateKey::GetModulus怎么用?C++ PrivateKey::GetModulus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa::PrivateKey
的用法示例。
在下文中一共展示了PrivateKey::GetModulus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintPrivateKey
void PrintPrivateKey(const RSA::PrivateKey& key)
{
cout << "n: " << key.GetModulus() << endl;
cout << "d: " << key.GetPrivateExponent() << endl;
cout << "e: " << key.GetPublicExponent() << endl;
cout << "p: " << key.GetPrime1() << endl;
cout << "q: " << key.GetPrime2() << endl;
}
示例2: printPrivateKey
static void printPrivateKey(RSA::PrivateKey key)
{
///////////////////////////////////////
// Generated Parameters
const Integer& n = key.GetModulus();
const Integer& p = key.GetPrime1();
const Integer& q = key.GetPrime2();
const Integer& d = key.GetPrivateExponent();
const Integer& e = key.GetPublicExponent();
cout << "RSA Parameters:" << endl;
cout << " n: " << n << endl;
cout << " p: " << p << endl;
cout << " q: " << q << endl;
cout << " d: " << d << endl;
cout << " e: " << e << endl;
cout << endl;
}
示例3: file
extern "C" int rsa_pss_sign(const char *key_file, const unsigned char *msg,
int len, unsigned char *sig_buf, unsigned char *modulus_buf)
{
try {
AutoSeededRandomPool rng;
FileSource file(key_file, true);
RSA::PrivateKey key;
ByteQueue bq;
// Load the key
file.TransferTo(bq);
bq.MessageEnd();
key.BERDecodePrivateKey(bq, false, bq.MaxRetrievable());
// Write the modulus
Integer mod = key.GetModulus();
// error check
if (mod.ByteCount() != RCM_RSA_MODULUS_SIZE)
throw std::length_error("incorrect rsa key modulus length");
for (int i = 0; i < mod.ByteCount(); i++)
modulus_buf[i] = mod.GetByte(i);
// Sign the message
RSASS<PSS, SHA256>::Signer signer(key);
size_t length = signer.MaxSignatureLength();
SecByteBlock signature(length);
length = signer.SignMessage(rng, msg, len, signature);
// Copy in reverse order
for (int i = 0; i < length; i++)
sig_buf[length - i - 1] = signature[i];
}
catch(const CryptoPP::Exception& e) {
cerr << e.what() << endl;
return 1;
}
catch(std::length_error& le) {
cerr << "Error: " << le.what() << endl;
return 1;
}
return 0;
}
示例4: 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;
}
示例5: pubkey
int
main(int argc, char ** argv)
{
if (argc != 2) {
cout << "Usage: keygen <outputname>" << endl;
return -1;
}
AutoSeededRandomPool rng;
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 3072);
RSA::PublicKey pubkey(params);
RSA::PrivateKey privkey(params);
Integer m = params.GetModulus();
Integer p = params.GetModulus();
Integer q = params.GetModulus();
Integer priv = params.GetPrivateExponent();
Integer pub = params.GetPublicExponent();
string privname = string(argv[1]).append(".priv");
string pubname = string(argv[1]).append(".pub");
CryptoEngine::pubkeyToFile(pubkey, pubname);
CryptoEngine::privkeyToFile(privkey, privname);
cout << "Loading and verifying..." << endl;
RSA::PrivateKey newpriv = CryptoEngine::privkeyFromFile(privname);
RSA::PublicKey newpub = CryptoEngine::pubkeyFromFile(pubname);
cout << (m == newpriv.GetModulus() ? "TRUE" : "FALSE") << endl;
cout << (priv == newpriv.GetPrivateExponent() ? "TRUE" : "FALSE") << endl;
cout << (pub == newpriv.GetPublicExponent() ? "TRUE" : "FALSE") << endl;
cout << (m == newpub.GetModulus() ? "TRUE" : "FALSE") << endl;
cout << (pub == newpub.GetPublicExponent() ? "TRUE" : "FALSE") << endl;
return 0;
}