[Ethereum] Using Ethereum for data encryption

contract-designencryption

I'm trying to find a way to use an ethereum address/solidity/web3 for text encryption , but i'm not even sure it's possible to get the public key from the address(hash of the pubkey) using secp256k1 to get the publickey ? or if there is any other way to access it client side? if so, would the user be able to decrypt the data using it's passphrase(ethereum passphrase )? so that everything would happen client side but the data would be stored encrypted on the chain ?

I know none of this is really meant to do any of that but i'm trying to store encrypted data on the blockchain without having to rely on a server to store keys as much as possible but can't seems to find a way.

tldr:

Ethereum + data = encrypted data

encrypted data + ethereum + passphrase = data

Best Answer

You can extract an address and public key from a signature - see ecrecover.

There are several approaches you could take to do what you want to accomplish. One would be to store public keys in a contract. When I want to send someone an encrypted message I grab their public key through a contract, encrypt the data and send it. They will be able to decrypt with the associated private key.

One thing to keep in mind, anything your store on the blockchain can be read by anyone.

Related Topic