1

Im wrting a dapp which holds / manages sensitive data which might need to be encrypted and decrypted and push again into chain.

I know it is not safe to encrypt data in smart contract,which is why Im thinking of off-chain encryption mechanism . I thought to encrypt data using public key and then decrypt using private key . However I found that popular wallet s/w like metamask doesnt allow this.

1.What are the possible ways to acheive this or any other better ways? (I thought managing users eth keys is not so safe)

2.If using custom keys for encryption, Is it ok using a keymanagement tool like Google KMS or Amazon Kms to manage keys and encrypt data?

0

You can encrypt data with the public key and decrypt it with the private key offchain with standard encryption, in particular using Elliptic Curve Integrated Encryption Scheme (ECIES)

An example in python using ethereum keys:
https://github.com/tritone11/eth-ecies-py

In Rust:
https://github.com/tritone11/rust-eth-ecies

In javascript:
https://github.com/libertylocked/eth-ecies

In python, pyelliptic is sometimes a pain in the ass, you can obtain the same result following this:
https://github.com/ethereum/trinity/blob/master/p2p/ecies.py

  • To encrypt data off-chain , we need public and private keys . But how do we get them ? As mentioned in question, Popular wallet programs like metamask will neither allow to access keys nor will provide encrypt / decrypt methods . Isnt it complex to write own wallet program which manages keys and off-dapp functionality? – kulakarni dheeraj Feb 12 at 12:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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