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.
bip39 specification for generating master public keys and private keys and their 2**32 -1 child keys.
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.
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.
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.
from ecies.utils import generate_eth_key
from ecies import encrypt, decrypt
k = generate_eth_key() ##Instead of generating a new key, you can use sep256k1 keys generated with bip39 specifications.
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'