We are making a system where users can share files with other people but nobody should be able to figure out that all these different files belongs to same user on blockchain.

these are the steps we have followed.

  1. bip39 specification for generating master public keys and private keys and their 2**32 -1 child keys.

  2. If a user wants to store this file, A new child key will be generated with a new AES key will be generated. The file will be encrypted with this AES key (GCM) mode,appending nonce and tag with ciphertext. AES will be encrypted with this child private key.

  3. Now float a contract, with the location of this encrypted data, encrypted AES key and child public key and saved on the address generated from the public key based on some mechanism.

  4. If a user wants to share this file with other user, just generate a key based on the other user public key and users private key, and encrypt the AES with this common key so the other user can decrypt and read it.

My question is, How to encrypt AES key with secp256k1 keys since I couldnt find any implementation of this in either python or golang. The other question is, Is it safe to encrypt AES keys with child secp256k1 keys.

  • $\begingroup$ The first part of the question is off topic! $\endgroup$
    – kelalaka
    Commented Oct 12, 2018 at 17:04

1 Answer 1


I figured out an Answer, https://pypi.org/project/eciespy/, this library uses private/public key generated from Sep256k1 curve for encryption and decryption.

from ecies.utils import generate_eth_key
from ecies import encrypt, decrypt
k = generate_eth_key()
prvhex = k.to_hex()
pubhex = k.public_key.to_hex()
data = b'this is a test'
decrypt(prvhex, encrypt(pubhex, data))
b'this is a test'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.