What is the recommended way of encrypting a short std::string
into another std::string
using the openssl
C library (not the command-line tool of the same name) using a public keyfile, and knowing the algorithm? (in this case the string is no larger than ~100 bytes, keyfile is in .pem
format, algorithm can be any asymmetric one like RSA/ECDSA/etc).
I am looking to write a function with an interface like so: bool EncryptString(const std::string& InStr, const std::string& InPublicKey, std::string& OutString)
.
Looking through documentation it seems like EVP_PKEY_encrypt
is the function to use, which requires an EVP_PKEY_CTX *ctx
variable. My assumption is, this variable should be initialized with EVP_PKEY_CTX_new
, which in turn requires an EVP_PKEY *pkey
and an ENGINE *e
. Those I don't know how to initialize, and searching through the documentation leaves me very confused.
Maybe these functions are not the easiest approach, I am not familiar with this library at all and have no cryptography knowledge. I simply care about a black-box way of converting a string to an encrypted string.
Thank you
InStr
that I need to encrypt is very short ~100bytes, no longer than an AES key, so speed should not be a concern. It can be any short string, including an AES key. Therefore I assume it's appropriate to use RSA/ECDSA on it directly. – Manifoldopenssl
library go. I am quite surprised how hard it is to find information on a presumably simple task, in one of the most used encryption libraries. But it might be that my comprehension of the topics involved was too surface-level. – Manifold