Hi every one 
I want to display the keys RSA in a string of characters
here  the code 
thanks

-- 
You received this message because you are subscribed to "Crypto++ Users". More 
information about Crypto++ and this group is available at 
http://www.cryptopp.com and 
http://groups.google.com/forum/#!forum/cryptopp-users.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
// Linux help: http://www.cryptopp.com/wiki/Linux

// Debug:
// g++ -g -ggdb -O0 -Wall -Wextra -Wno-unused -Wno-type-limits -I. -I/usr/include/cryptopp cryptopp-key-gen.cpp -o cryptopp-key-gen.exe -lcryptopp

// Release:
// g++ -O2 -Wall -Wextra -Wno-unused -Wno-type-limits -I. -I/usr/include/cryptopp cryptopp-key-gen.cpp -o cryptopp-key-gen.exe -lcryptopp && strip --strip-all cryptopp-key-gen.exe
//////////////////////////




#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <iostream>



#include "cryptopp/integer.h"
#include "cryptopp/aes.h"

#include "cryptopp/cryptlib.h"

#include "cryptopp/filters.h"

#include "cryptopp/osrng.h"

#include "cryptopp/hex.h"

#include "cryptopp/modes.h"

#include <stdio.h>

#include <iostream>

#include <string>

#include <iomanip>

#include <string.h>

using namespace std;

using namespace CryptoPP;

using CryptoPP::AutoSeededRandomPool;

using CryptoPP::StringSink;

using CryptoPP::StreamTransformation;

using CryptoPP::StreamTransformationFilter;


#include <iostream>
using std::cout;
using std::endl;

#include "cryptopp/integer.h"
using CryptoPP::Integer;



#include <iomanip>
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/filters.h"
//#include "ns3/core-module.h"
using namespace CryptoPP;
using namespace std;


#include "cryptopp/hex.h"

#include "cryptopp/files.h"

#include <iostream>

#include "cryptopp/sha.h"

#include "cryptopp/filters.h"

#include "cryptopp/cryptlib.h"

#include  "cryptopp/sha.h"

#include <iostream>
using CryptoPP::Integer;

#include "cryptopp/nbtheory.h"
using CryptoPP::ModularExponentiation;

#include "cryptopp/dh.h"
using CryptoPP::DH;

#include "cryptopp/secblock.h"
using CryptoPP::SecByteBlock;

#include "cryptopp/hex.h"
using CryptoPP::HexEncoder;


using CryptoPP::StringSink;

 using namespace CryptoPP;

using CryptoPP::StringSink;

using std::string;
///////////
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include <string>
using std::string;

#include <stdexcept>
using std::runtime_error;

#include <cryptopp/queue.h>
using CryptoPP::ByteQueue;

#include <cryptopp/files.h>
using CryptoPP::FileSource;
using CryptoPP::FileSink;

#include "cryptopp/dsa.h"
using CryptoPP::DSA;

#include "cryptopp/rsa.h"
using CryptoPP::RSA;

#include "cryptopp/base64.h"
using CryptoPP::Base64Encoder;
using CryptoPP::Base64Decoder;

#include <cryptopp/cryptlib.h>
using CryptoPP::PrivateKey;
using CryptoPP::PublicKey;
using CryptoPP::BufferedTransformation;

#include "cryptopp/osrng.h"
using CryptoPP::AutoSeededRandomPool;

void SavePrivateKey(const string& filename, const PrivateKey& key);
void SavePublicKey(const string& filename, const PublicKey& key);

void SaveBase64PrivateKey(const string& filename, const PrivateKey& key);
void SaveBase64PublicKey(const string& filename, const PublicKey& key);

void SaveBase64(const string& filename, const BufferedTransformation& bt);
void Save(const string& filename, const BufferedTransformation& bt);

void LoadPrivateKey(const string& filename, PrivateKey& key);
void LoadPublicKey(const string& filename, PublicKey& key);

void LoadBase64PrivateKey(const string& filename, PrivateKey& key);
void LoadBase64PublicKey(const string& filename, PublicKey& key);

void LoadBase64(const string& filename, BufferedTransformation& bt);
void Load(const string& filename, BufferedTransformation& bt);
int key();
int main(int argc, char** argv)
{
	key();
	return 0;
}


int key ()
{
	
	
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, 2048);

		RSA::PublicKey rsaPublic(rsaPrivate);
/*HexEncoder privString(new StringSink(privResult));
HexEncoder pubString(new StringSink(pubResult));
*/
/*SecByteBlock privKey(dh.PrivateKeyLength());
		SecByteBlock pubKey(dh.PublicKeyLength());
		dh.GenerateKeyPair(rnd, privKey, pubKey);*/

/*string key1;
		HexEncoder hex(new StringSink(key1));

		key1= "0x";		
		hex.Put(rsaPrivate.BytePtr(), rsaPrivate.SizeInBytes());
		hex.MessageEnd();*/
		//cout <<" priv "<<rsaPrivate.<<endl ;

		SavePrivateKey("rsa-privatekey  Node 0 ", rsaPrivate);
		SavePublicKey("rsa-publickey   Node 0", rsaPublic);
		
		/*SavePrivateKey("rsa-privatekey  Node 1 ", rsaPrivate);
		SavePublicKey("rsa-publickey Node 1", rsaPublic);
		
		
		SavePrivateKey("rsa-private.key  Node 2 ", rsaPrivate);
		SavePublicKey("rsa-public.key Node 2", rsaPublic);


	SavePrivateKey("rsa-private.key  Node 3", rsaPrivate);
		SavePublicKey("rsa-public.key Node 3", rsaPublic);
		
			SavePrivateKey("rsa-private.key  Node 4 ", rsaPrivate);
		SavePublicKey("rsa-public.key Node 4", rsaPublic);
			SavePrivateKey("rsa-private.key  Node ", rsaPrivate);
		SavePublicKey("rsa-public.key Node 2", rsaPublic);
			SavePrivateKey("rsa-private.key  Node 2 ", rsaPrivate);
		SavePublicKey("rsa-public.key Node 2", rsaPublic);*/
		////////////////////////////////////////////////////////////////////////////////////

		// http://www.cryptopp.com/docs/ref/struct_d_s_a.html
		/*DSA::PrivateKey dsaPrivate;
		dsaPrivate.GenerateRandomWithKeySize(rnd, 1024);

		DSA::PublicKey dsaPublic;
		dsaPrivate.MakePublicKey(dsaPublic);

		SavePrivateKey("dsa-private.key", dsaPrivate);
		SavePublicKey("dsa-public.key", dsaPublic);*/

		////////////////////////////////////////////////////////////////////////////////////

		RSA::PrivateKey r1, r2;
		r1.GenerateRandomWithKeySize(rnd, 3072);

		SavePrivateKey("rsa-roundtrip.key", r1);
		LoadPrivateKey("rsa-roundtrip.key", r2);

		r1.Validate(rnd, 3);
		r2.Validate(rnd, 3);

		if(r1.GetModulus() != r2.GetModulus() ||
		   r1.GetPublicExponent() != r2.GetPublicExponent() ||
		   r1.GetPrivateExponent() != r2.GetPrivateExponent())
		{
			throw runtime_error("key data did not round trip");
		}
		
		////////////////////////////////////////////////////////////////////////////////////

		cout << "Successfully generated and saved RSA keys" << endl;
	}

	catch(CryptoPP::Exception& e)
	{
		cerr << e.what() << endl;
		return -2;
	}

	catch(std::exception& e)
	{
		cerr << e.what() << endl;
		return -1;
	}
return 0	;
	
	
}

                


 void associatekey(int  s){
cout<<"la générationde clé pour chaque Noeud"<<endl;
	for (int  i = 0; i < s; ++i){
		
		cout <<"Node : "<< i << "----> "<< endl; 
		//cout <<  genrateKey ()<<endl;
		
     
    }
	
}





void SavePrivateKey(const string& filename, const PrivateKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;
	key.Save(queue);

	Save(filename, queue);
}

void SavePublicKey(const string& filename, const PublicKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;
	key.Save(queue);

	Save(filename, queue);
}

void Save(const string& filename, const BufferedTransformation& bt)
{
	// http://www.cryptopp.com/docs/ref/class_file_sink.html
	FileSink file(filename.c_str());

	bt.CopyTo(file);
	file.MessageEnd();
}

void SaveBase64PrivateKey(const string& filename, const PrivateKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;
	key.Save(queue);

	SaveBase64(filename, queue);
}

void SaveBase64PublicKey(const string& filename, const PublicKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;
	key.Save(queue);

	SaveBase64(filename, queue);
}

void SaveBase64(const string& filename, const BufferedTransformation& bt)
{
	// http://www.cryptopp.com/docs/ref/class_base64_encoder.html
	Base64Encoder encoder;

	bt.CopyTo(encoder);
	encoder.MessageEnd();

	Save(filename, encoder);
}

void LoadPrivateKey(const string& filename, PrivateKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;

	Load(filename, queue);
	key.Load(queue);	
}

void LoadPublicKey(const string& filename, PublicKey& key)
{
	// http://www.cryptopp.com/docs/ref/class_byte_queue.html
	ByteQueue queue;

	Load(filename, queue);
	key.Load(queue);	
}

void Load(const string& filename, BufferedTransformation& bt)
{
	// http://www.cryptopp.com/docs/ref/class_file_source.html
	FileSource file(filename.c_str(), true /*pumpAll*/);

	file.TransferTo(bt);
	bt.MessageEnd();
}

void LoadBase64PrivateKey(const string& filename, PrivateKey& key)
{
	throw runtime_error("Not implemented");
}

void LoadBase64PublicKey(const string& filename, PublicKey& key)
{
	throw runtime_error("Not implemented");
}

void LoadBase64(const string& filename, BufferedTransformation& bt)
{
	throw runtime_error("Not implemented");
}

Reply via email to