Miro Krsjak
Miro Krsjak

Reputation: 363

How to encrypt a message using EC in python?

I'm using the https://cryptography.io/en/latest/hazmat/primitives/asymmetric/ec/# library and there is no option for EC encryption, just signing. Is there a way to encrypt text using the EC or do I have to use RSA?

Upvotes: 0

Views: 1388

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 93948

No, you can use ECIES. IES stands for Integrated Encryption Scheme. It uses the key agreement variant of EC to calculate a symmetric key, which can then be used for encryption, e.g. using AES/GCM.

The disadvantage is that you need to send the public key of the data specific key pair together with the ciphertext. Then again, RSA encryption also expands the ciphertext compared to the plaintext.

Implementing IES is not that hard, but still harder than simply calling a function to perform RSA encryption - you need to perform key pair generation, key agreement including key derivation and symmetric encryption/decryption after all.

Note that you should use different keys for signing and decryption, using keys for different purposes can be very dangerous.

Upvotes: 1

Related Questions