Created
August 25, 2017 04:25
-
-
Save Korvox/e66cbbef3b4ed31b337dd2e00e6f3b9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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