Reference: https://wiki.openssl.org/index.php/Manual:EVP_SealInit%283%29

I want to securely share a symmetrical key between two endpoints using OpenSSL's EVP interface. Transferring the encrypted symmetrical key and decrypting it on the other end works fine, but that leaves me with only the sender having it, since the SealInit function generates a random symmetrical key and immediately encrypts it with the receiver's public key.

So my question is, how am I supposed to be using these functions?

I could solve it by:

a) Generating a symmetrical key beforehand and encrypting it with the receiver's public key, which makes some part of the sealing operation pointless


b) Using a separate symmetrical key for both the sender and receiver, which seems needlessly complex

Since neither option seems like a good solution to me, I think I must be missing something or misunderstanding some basic concepts, as encryption is new to me.

Thank you for reading my question.

  • Instead of using EVP_SealInit directly, you could write your own function which is quite similar, but which allows you to specify the symmetric key. The EVP_SealInit source code would be fairly easy to copy; you then modify/remove the portion where EVP_CIPHER_CTX_rand_key is called to generate the random key, and instead use one you supply to your function.
    – Castaglia
    Mar 31, 2016 at 4:04

1 Answer 1


Yes, EVP_{Seal,Open}* do 'hybrid' encryption: symmetric-encrypt the data with a nonce key, and publickey-encrypt that key to the recipient(s), and decrypt accordingly. (EVP_Digest{Sign,Verify}* similarly do hybrid signing: symmetric-hash the data and public-key sign the hash.) If you don't want this functionality, don't use these routines.

If you want to publickey-encrypt and decrypt a small amount of data, such as a symmetric key, use EVP_PKEY_{encrypt,decrypt}{_init,}. Most symmetric keys are just random bytes (or bits) and you can generate with RAND_bytes. Assuming you want to subsequently symmetric encrypt and decrypt data with that key, see EVP_{Encrypt,Decrypt}* or EVP_Cipher* which has a flag to select direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .