ECIES Encryption - Example
Now, let's demonstrate how the ECIES encryption scheme works in practice in Python. We shall use a Python library eciespy
:
A sample Python code to generate public / private key pair and encrypt and decrypt a message using ECIES is:
Run the above code example: https://repl.it/@nakov/ECIES-in-Python.
The above code is pretty simple: just generate ECC public + private key pair using ecies.utils.generate_eth_key()
and call the ecies.encrypt(pubKey, msg)
and decrypt(privKey, encryptedMsg)
functions from the eciespy
library.
The output form the above code looks like this:
The Python eciespy
library internally uses ECC cryptography over the secp256k1 curve + AES-256-GCM authenticated encryption. Note that the above encrypted message holds together 4 values: {cipherPubKey, AES-nonce, authTag, AES-ciphertext}
, packed in binary form and not directly visible from the above output.
Last updated