All,

I am new to using crypto++ 5.1 and wish to know a few, hopefully simple,
things:

1) Is this the correct way to copy a public key (SecByteBlock) to a
std::string?

string data;
AutoSeededRandomPool *arng = new AutoSeededRandomPool;
RandomNumberGenerator &rng = *dynamic_cast<RandomNumberGenerator *>
(arng);
   
DH dh (rng, 128);

SecByteBlock val (dh.AgreedValueLength ());
SecByteBlock local_public_key (dh.PublicKeyLength ());
SecByteBlock local_private_key (dh.PrivateKeyLength ());

fill (val.begin (), val.end (), 0);
dh.GeneratePrivateKey (rng, local_private_key);
dh.GeneratePublicKey (rng, local_private_key, local_public_key);

StringSource (local_public_key, true, new HexEncoder (new StringSink
(data)));

cout << data << endl;

If this is the correct way then I can now send it over a socket to
another machine.

2) If all the above is good how do I change the string back to a
SecByteBlock at the other end?

Or is there a better way to transfer public keys between remote hosts?

Regards

Jim Vanns

-- 
James Vanns BSc (Hons) MCP
Linux Systems Administrator
Senior Software Engineer (Linux / C & C++)
Canterbury Christ Church University College
Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x24045370

Reply via email to