I would like to use Elliptic Curve Cryptography to asymmetrically encrypt data. That is encrypt data using a public ECC key, so that only someone with the corresponding private key can decrypt it.

I'm aware you cannot just encrypt any arbitrary data with ECC (or with any asymmetric encryption scheme for that matter) so typically you'd just encrypt a one-time random key that is smaller than the ECC key size, say 128 bit. And then encrypt the actual data using a simple symmetric cipher (like AES) with that random key.

I just learned it doesn't work quite like that with ECC, but a scheme like ECIES does something similar adapted for ECC.

My question: is there a way to do this with openssl or a similar commonly available tool?

So suppose I have an ECC keypair e.g. MyPrivateEd25519Key.pem and MyPublicEd25519Key.pem (or secp256k1 or secp521r1 or whatever is suitable) and a data file. Can I encrypt the file using the public ECC key, and then decrypt the result using the private key?

I'm quite unclear as to how I can pull this off (if at all) with openssl.

  • Read this. It might help get you going. Commented Oct 1, 2020 at 15:46
  • @SeñorCMasMas thanks but that seems to be mostly about certificates, and signing requests. I'm really just looking for encryption+decryption arbitrary data, no certificates or signatures are involved.
    – RocketNuts
    Commented Oct 1, 2020 at 16:09
  • I couldn't find what you are looking for but I am mostly sure that it exists.. KEEP LOOKING! Commented Oct 1, 2020 at 16:11

1 Answer 1


Yes, you can, but you'll need to manipulate all of the primitives on your own.

Here is an example: https://github.com/insanum/ecies

  • It is better to include the relevant parts into the answer and not only posting a link.
    – zx485
    Commented Aug 25, 2021 at 1:00
  • Yes, hence me giving a rough description first, the link is just a worked example. What I'm not going to do is paste several hundred lines of someone else's C code into my answer - what RocketNuts asked is actually quite complex.
    – jkflying
    Commented Aug 26, 2021 at 8:02
  • The linked implementation does not use a KDF to remove bias from the key exchange result. This is mentioned in an issue.
    – PiQuer
    Commented Sep 13, 2023 at 7:41

You must log in to answer this question.

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