I have the following text string:
This is a test message.
Using my bitcoin public key (bitcoin address?), how can I encrypt this message?
How would I decrypt the message using a bitcoin private key?
I have the following text string:
This is a test message.
Using my bitcoin public key (bitcoin address?), how can I encrypt this message?
How would I decrypt the message using a bitcoin private key?
Yes, this is possible.
However, I want to upfront state that this is not advisable for multiple reasons:
A scheme called ECIES exists that lets you leverage elliptic curve keys to create an encryption system.
In short, it works by:
The sender:
The recipient:
with associated public key k = kG
.. here it should be capital K = kG
; and AECEnc
should be AESEnc
If you want to encrypt messages, you should use a proper message/file encryption tool like PGP/GPG. Homebrewed cryptography using bitcoin things is prone to having poor security properties.
Be sure to follow the warnings given previously in other answers, but for the record this was implemented in a project called Bitmessage. The main implementation is in Python at https://github.com/Bitmessage/PyBitmessage. There is also an npm module for node.js that implemented this for the server and browser using openssl c libraries under the hood: eccrypto
:
Install dependencies
$ npm install -g eccrypto
index.js
var crypto = require("crypto");
var eccrypto = require("eccrypto");
var privateKeyA = crypto.randomBytes(32);
var publicKeyA = eccrypto.getPublic(privateKeyA);
var privateKeyB = crypto.randomBytes(32);
var publicKeyB = eccrypto.getPublic(privateKeyB);
// Encrypting the message for B.
eccrypto.encrypt(publicKeyB, Buffer("msg to b")).then(function(encrypted) {
// B decrypting the message.
eccrypto.decrypt(privateKeyB, encrypted).then(function(plaintext) {
console.log("Message to part B:", plaintext.toString());
});
});
// Encrypting the message for A.
eccrypto.encrypt(publicKeyA, Buffer("msg to a")).then(function(encrypted) {
// A decrypting the message.
eccrypto.decrypt(privateKeyA, encrypted).then(function(plaintext) {
console.log("Message to part A:", plaintext.toString());
});
});