eciespy

raw JSON →
0.4.6 verified Fri May 01 auth: no python

Elliptic Curve Integrated Encryption Scheme (ECIES) for secp256k1 and curve25519 in Python. Current version 0.4.6, supports Python >=3.9. Active development with multi-curve support and custom key pair generation.

pip install eciespy
error ImportError: cannot import name 'encrypt' from 'eciespy'
cause Wrong import path; the package is 'eciespy' but the module is 'ecies'.
fix
Use 'from ecies import encrypt, decrypt' instead of 'eciespy'.
error ValueError: Public key format is not correct
cause Public key not in valid hex, or missing '04' prefix for uncompressed key.
fix
Ensure public key is hex (130 or 66 characters) and starts with '04' for uncompressed.
error AttributeError: module 'ecies.utils' has no attribute 'generate_key_pair'
cause Function was deprecated and moved in v0.4.5.
fix
Use 'from ecies.keys import generate_key_pair' or HomemadeKey.
breaking In v0.4.5, functions in ecies.utils are deprecated and will be removed after v0.5.0. Use ecies.keys or ecies.consts instead.
fix Replace ecies.utils.xxx with new API from ecies.keys or ecies.consts.
deprecated The eth-keys dependency is optional since v0.4.4 and will be removed eventually. Ethereum-style keys may stop working.
fix Switch to homemade key pairs via ecies.keys.HomemadeKey or use the built-in key generation.
gotcha Keys must be hex strings with or without '0x' prefix. Encryption expects uncompressed public key (130 hex chars with '04' prefix) or compressed (66 hex chars).
fix Ensure public key is valid uncompressed '04' + 64 bytes or compressed '02'/'03' + 32 bytes.

Basic encrypt/decrypt with secp256k1 keys.

import os
from ecies import encrypt, decrypt

# Generate a private key (hex)
private_key = os.urandom(32).hex()
# Derive public key (hex, uncompressed)
# ecies can also use Ethereum-style keys
# For quickstart, we use a known key pair:
privkey = '0x0000000000000000000000000000000000000000000000000000000000000001'
pubkey = '0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
# Encrypt
plaintext = b'Hello, ECIES!'
ciphertext = encrypt(pubkey, plaintext)
# Decrypt
assert decrypt(privkey, ciphertext) == plaintext
print('Success!')