Hi Jeff, Many thanks. Enclosed is the whole codes.
//General paramters int Network_Nodes =100; //This parameter is the total number of nodes in the network. This is used to create public and private key pairs. int Block_Size=10; // The size of blocks in the bc int BC_lenght=0; // This indicates the lenghtes of the BC, i.e. the total number of blocks added to the BC. int Fin_BC_size =20; //This indicates the final size of the BC. std::vector<CryptoPP::RSA::PrivateKey> prk; std::vector<CryptoPP::RSA::PublicKey> pk; std::vector<std::string> prev_t; //this keeps the ID of the previous trnasaction for each node. struct Block { std::string block_hash; std::string block_num; struct transactions { std::string TransactionID; std::string previousTransactionID; std::string PK; std::string Sign; }; std::vector<transactions> trans; }; std::vector<Block> BC; //////////////////////////////////////////These are included for salsa using CryptoPP::Salsa20; using CryptoPP::AutoSeededRandomPool; using std::cout; using std::endl; using std::string; //////////////////////////////////////////End of encludes for Salsa int generatekey() { for (int i=0;i<Network_Nodes;i++) { CryptoPP::AutoSeededRandomPool rng; CryptoPP::InvertibleRSAFunction param; param.GenerateRandomWithKeySize(rng,1536); CryptoPP::RSA::PrivateKey privatekey(param); CryptoPP::RSA::PublicKey publickey (param); prk.push_back(privatekey); pk.push_back(publickey); } return 0; } /////////////////////////////////////////////////////////////// void initialization() { for (int i=0;i<=Fin_BC_size;i++) { prev_t.push_back("NULL"); } } ///////////////////////////////////////////////////////////////// void populate_bc () { int stored_trans_in_block=0; // the total number of transactions which are stored in a single block. temporary to decide on whether to change the block-number or not. int node=0; //indicates which node we are currently using to fill the BC. std::string block_content,trans_cont; //collects all data in the block, used for calcluating the hash of the block. std::string pkstring; //the string of the PK std::string signature; std::string mes ="Used for signature"; Block::transactions tra; // First we need to push empty classes for both BC and transactions thus we can fill it later. BC.push_back(Block()); BC[BC_lenght].trans.push_back(Block::transactions()); if (prev_t[node]=="NULL") { // BC[BC_lenght].trans[stored_trans_in_block].previousTransactionID =="NULL"; pk[node].BEREncode(CryptoPP::StringSink(pkstring).Ref()); BC[BC_lenght].trans[stored_trans_in_block].PK=pkstring; // CryptoPP::RSASS<CryptoPP::PSS, CryptoPP::SHA1>::Signer signer(prk[2]); CryptoPP::AutoSeededRandomPool rng; CryptoPP::RSASSA_PKCS1v15_SHA_Signer signer(prk[node]); CryptoPP::StringSource ss1(mes, true, new CryptoPP::SignerFilter(rng, signer, new CryptoPP:: StringSink(signature) ) // SignerFilter ); // StringSource /* CryptoPP::StringSource ss1(mes, true, new CryptoPP::SignerFilter(rng, signer, new CryptoPP::HexEncoder( new CryptoPP::StringSink(signature))));*/ // BC[BC_lenght].trans[stored_trans_in_block].Sign=signature; } pk[2].BEREncode(CryptoPP::StringSink(pkstring).Ref()); tra.PK = pkstring; tra.previousTransactionID= " "; tra.Sign=" "; tra.TransactionID=" "; BC[0].trans.push_back(tra); } int main(int argc, const char * argv[]) { //1) create "Netwrok_Nodes" number of key pair sets generatekey(); //2) initilaization initialization(); //3) create blockchain with the above nodes. populate_bc(); } On Friday, August 11, 2017 at 12:23:08 PM UTC+10, Jeffrey Walton wrote: > > > I installed crypto++ on my mac and try to run a simple code on xcode. I >> can create keys using the following: >> >> CryptoPP::AutoSeededRandomPool rng; >> >> CryptoPP::InvertibleRSAFunction param; >> >> param.GenerateRandomWithKeySize(rng,1536); >> >> CryptoPP::RSA::PrivateKey privatekey(param); >> >> CryptoPP::RSA::PublicKey publickey (param); >> >> prk.push_back(privatekey); >> >> pk.push_back(publickey); >> > > The push_back's look unusual. Do something else. > > If you show the code that calls the snippet above, we might be able to > suggest something. > > But when I try to sign a message it goes to threat. I do not know what to >> do with it. The exact threat message is: >> >> Thread 1: EXC_BAD_ACCESS >> >> >> I am using the following code to sign: >> >> CryptoPP::StringSource ss1(mes, true, >> >> new CryptoPP::SignerFilter(rng, signer, >> >> new CryptoPP::StringSink(signature) >> >> ) // SignerFilter >> >> ); // StringSource >> > > This looks OK. > > There's also some RSA examples on the wiki at > https://www.cryptopp.com/wiki/RSA_Cryptography. > > Jeff > -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to cryptopp-users-unsubscr...@googlegroups.com. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- 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.