Post
Topic
Board Development & Technical Discussion
Re: Encrypt a message using Bitcoin Public Key and decrypt with private key?Like PGP
by
kzv
on 24/10/2019, 12:19:45 UTC
What do you call the receiver private key? It's the private key of the message receiver? Why would you need to send him your public key? If he's the message receiver it's him who need to send you his own public key, no?

Example
Alice want to send encrypted message to Bob
Alice and Bob have keypairs (alice_public_key & alice_private_key; bob_public_key & bob_private_key)

Alice need to know only Bob's public key. This bob_public_key can be obtained from any Bob's transaction in blockchain.
Alice calculate
Code:
shared_private_key = alice_private_key * bob_public_key

Now Alice can encrypt any message with the shared_private_key like this:
Code:
encrypted_message = AES_ENCRYPT( 'hello Bob!', shared_private_key )

Now Alice can send to Bob encrypted_message and alice_public_key.

Bob calculate
Code:
shared_private_key = bob_private_key * alice_public_key

Now Bob can decrypt message like this
Code:
decrypted_message = AES_DECRYPT( encrypted_message, shared_private_key )
assert( decrypted_message ==  'hello Bob!' )