String and Stringsource (load):
String spki = ...; Stringsource SS (Spki, True/*pumpall*/); RSA::P ublickey publickey;publickey.load (ss);
Vector and Arraysource (load):
Vector<byte> Spki = ...; Arraysource as (&spki[0], Spki.length (), true/*pumpall*/); RSA::P ublickey publickey;publickey.load (AS);
String and Stringsink (save)
String Spki; Stringsink SS (SPKI); RSA::P ublickey publickey (...); Publickey.save (ss);
Vector (Save)
Below is an example of saving to and loading from a std::vector . You have a intermediate to ByteQueue save because you can ' t easily create a VectorSink .
Autoseededrandompool PRNG; RSA::P rivatekey pk1, Pk2;pk1. Initialize (PRNG, 1024); Bytequeue QUEUE;PK1. Save (queue);vector<byte> spki;spki.resize (queue. Maxretrievable ()); Arraysink AS1 (&spki[0], spki.size ()), queue. CopyTo (AS1); Arraysource AS2 (&spki[0], spki.size (), true);p K2. Load (AS2); bool valid = Pk2. Validate (PRNG, 3); if (valid) cout << "Validated private key" << endl;else cout << "Failed to Val Idate private Key "<< Endl;
We don ' t have an explicit VectorSink , and we can ' t easily create one because of an implicit expectation of traits_type::char_type . For example:
Using Cryptopp::stringsinktemplate;typedef stringsinktemplate< std::vector<byte> > VectorSink;In file Included from Cryptopp-test.cpp:65:in file included from/usr/local/include/cryptopp/files.h:5:/usr/local/include/ Cryptopp/filters.h:590:22:error:no member named ' Traits_type ' in ' std::vector<unsigned char, std::allocator <unsigned char> > ' typedef typename T::traits_type::char_type Char_type; ~~~^cryptopp-test.cpp:243:20:note:in instantiation of template class ' CRYPTOPP::STRINGSINKTEMPLATE<STD:: vector<unsigned Char, std::allocator<unsigned char> > > ' requested here Vectorsink vs (SPKI);
Http://c/questions/29050575/how-would-i-load-a-private-public-key-from-a-string-byte-array-or-any-other
crypto++ RSA reads public and private keys from a string