2

I want to send an encrypted message to a specific ETH address via the blockchain.

Hello, my secret.

Can I encrypt this message in the browser with the public key of the recipient's address? I understand that an ETH address is not a public key, but is it possible to somehow get it to a person who wants to send a message.

encode_public_key_ETH_address('Hello, my secret.') 
//=> 6ee825aafad19a0d759e1e0b

Send to blockchain.

So that only the recipient can decrypt it using the private key from the ETH address.

decode_private_key_ETH_address('6ee825aafad19a0d759e1e0b') 
//=> Hello, my secret.
YBul
  • 23
  • 3

1 Answers1

2

This is possible to do. But you will need the public key of the person you are sending a message to.

As you correctly said, an address is not a public key. But you also can't, in general, "extract" a public key from an address (to do so, you'd need to have a signed transaction from the address as well, see this question for more on this).

The good thing is that nobody should be afraid of sharing their public key with you.

EDIT: This link should help you; it explains how to get a public key from a signed transaction: Get public key of any ethereum account

Sky
  • 2,282
  • 2
  • 7
  • 26
  • Thank you. It turns out to get the public key knowing only the address is impossible. You can find out when the user will make a transaction. – YBul Jul 16 '22 at 21:48