Skip to content

Instantly share code, notes, and snippets.

@Korvox
Created Aug 25, 2017
Embed
What would you like to do?
// 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