1

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.

2
  • AES can use 256 bits keys and secp256k1 private keys are 256 bits, so it should be possible to use them interchangeably. But I cannot state that that practice is safe. For example to OpenPGP will create a new encryption key for each message that are unrelated to your personal keys.
    – Ismael
    Commented Sep 13, 2018 at 6:44
  • I wanted to encrypt AES keys with secp256k1 private keys, I just have posted an answer how to do that. Thanks. Commented Sep 13, 2018 at 8:07

1 Answer 1

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() ##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'

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.