Exercises: ECIES Encrypt / Decrypt
Write a program to encrypt / decrypt a message by public / private key using ECIES (Elliptic Curve Integrated Encryption Scheme). The encryption will require an EC public key and decryption will require the corresponding EC private key. Internally, use ECC cryptography based on a 256-bit elliptic curve by choice (e.g. brainpoolP256t1
) and symmetric encryption by choice (e.g. AES-256-CTR + MAC, AES-128-GCM or ChaCha20-Poly1305), along with key-derivation function by choice (e.g. PBKDF2).
You are free to choose between writing your own ECIES implementation, following the SECG-SEC-1 standard or use a standard ECIES library for your language, e.g.
Python: https://pypi.org/project/eciespy
JavaScript: https://github.com/bitchan/eccrypto
C, C++, PHP, Perl: https://github.com/jedisct1/libsodium
ECIES Encryption
Write a program to encrypt a message using the ECIES hybrid encryption scheme and a 256-bit ECC public key (2 * 256 bits).
The input consists of the public key in hex (at the first line, uncompressed, 128 hex digits) + plaintext message for encryption (at the second line).
The output is the hex-encoded encrypted message. It may hold the ECC ciphertext public key + the ciphertext + MAC code + the symmetric key algorithm parameters, but this depends very much on the underlying algorithms and implementation.
Sample input:
Sample output:
It will be different for each program execution due to the randomness in the encryption scheme:
ECIES Decryption
Write a program to decrypt an encrypted message created by the program from the previous example, using the ECIES hybrid encryption scheme and a 256-bit ECC private key.
The input consists of the private key in hex (at the first line, 64 hex digits) + encrypted message for decryption (at the second line).
The output is the decrypted plaintext message. In case or decryption problem (e.g. incorrect decryption key or broken encrypted message), display
Error: cannot decrypt the message
.
Sample input:
Sample output:
Sample input:
This example holds an incorrect decryption private key:
Sample output:
Last updated