Skip to content

Instantly share code, notes, and snippets.

@Korvox
Created August 25, 2017 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Korvox/e66cbbef3b4ed31b337dd2e00e6f3b9d to your computer and use it in GitHub Desktop.
Save Korvox/e66cbbef3b4ed31b337dd2e00e6f3b9d to your computer and use it in GitHub Desktop.
// g++ -lcryptopp rsa.cpp -o rsa
#include <iostream>
#include <string>
#include "cryptopp/rsa.h"
#include "cryptopp/osrng.h"
#include <cryptopp/files.h>
using namespace std;
using namespace CryptoPP;
int main(int argc, char** argv) {
AutoSeededRandomPool rng;
InvertibleRSAFunction params;
params.GenerateRandomWithKeySize(rng, 2048);
const Integer& n = params.GetModulus();
const Integer& p = params.GetPrime1();
const Integer& q = params.GetPrime2();
const Integer& d = params.GetPrivateExponent();
const Integer& e = params.GetPublicExponent();
cout << " n: " << n << endl;
cout << " p: " << p << endl;
cout << " q: " << q << endl;
cout << " d: " << d << endl;
cout << " e: " << e << endl;
RSA::PublicKey publicKey(params);
FileSink pubsink("pubkey.der");
publicKey.DEREncode(pubsink);
RSA::PrivateKey privateKey(params);
FileSink privsink("privkey.der");
privateKey.DEREncode(privsink);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment