I'm looking for two functions conceptually similar to these:
// returns the encrypted text
string encrypt( string public_key, string pass_phrase, string text );
// returns the original text
string decrypt( string private_key, string pass_phrase, string encrypted_text );
where string
could be a char*
, a std::string
or something easily convertible to those two. And where public_key
and private_key
can be basically anything, from keys generated with some commands (gpg/ssl stuff or whatever), to keys generated with other simple functions.
I've looked into a few cryptography libraries (libgcrypt, libgpgme, openssl ...), but it doesn't look easy at all to implement such functions with those libraries: they require a non-superficial knowledge about asymmetric encryption and a lot of code.
Anyway this task doesn't seem uncommon. How can I implement the two functions above?
std::string
, which is 8-bit clean and includes a length, separate from the contents of the string. – Orthodoxystring
to have a length embedded somewhere. Of course if strings arechar*
s, all of those parameters will need another one for the length: also keys (and potentially even plaint text) are binary. – Spermary