<p>You could use something like this <a href="https://github.com/bitchan/eccrypto" rel="nofollow noreferrer">eccrypto</a> (Do your own research on the security of this implementation). Also, doesn't appear to allow compressed public keys. <strong>Update</strong>: It now supports compressed keys as of <code>v1.1</code>.</p>

<p><strong>index.js</strong></p>

<pre><code>var crypto = require("crypto");
var eccrypto = require("eccrypto");

var privateKey = new Buffer("c337ded6f56c07205fb7b391654d7d463c9e0c726869523ae6024c9bec878878", "hex");

//var publicKey = eccrypto.getPublic(privateKey);
var publicKey = new Buffer("04730a151f545f5dcdb1c6d99fb1251f5c70f216f39ba2681bcf10db16bd582e6720bc881d51f25ffbe961df6a0af24a9d39a4db3d86a7f6b3f9bf4eaac0e4006b", "hex");

// Encrypting the message for B.
eccrypto.encrypt(publicKey, Buffer("msg")).then(function(encrypted) {
    console.log('Encrypted message ' + JSON.stringify(encrypted));
  // B decrypting the message.
  eccrypto.decrypt(privateKey, encrypted).then(function(plaintext) {
    console.log("Decrypted message: ", plaintext.toString());
  });
});
</code></pre>

<p><strong>Output</strong></p>

<pre><code>$ node index.js
Encrypted message {"iv":{"type":"Buffer","data":[204,13,168,25,80,255,9,233,111,60,165,204,180,126,53,65]},"ephemPublicKey":{"type":"Buffer","data":[4,192,3,65,241,134,65,186,52,52,250,61,208,189,216,167,122,206,156,152,27,173,69,152,37,138,164,5,54,189,227,88,37,243,220,183,22,204,235,37,212,110,207,66,225,244,25,92,69,223,247,175,218,228,134,210,247,190,211,248,239,77,183,21,36]},"ciphertext":{"type":"Buffer","data":[75,104,205,95,93,108,18,50,220,120,164,224,42,214,75,28]},"mac":{"type":"Buffer","data":[63,243,230,143,99,187,246,241,194,10,247,215,188,163,82,98,140,15,186,158,58,207,170,49,230,143,26,17,117,248,195,143]}}
Decrypted message:  msg
</code></pre>

CC BY-SA 4.0
2018-10-05T17:03:17.260Z
2018-12-16T19:11:06.950Z
2018-12-16T19:11:06.950Z
JBaczuk
<p>Are there any javascript libraries that can encrypt a 100 character text message using your bitcoin public key, but only be able to decrypt it with your bitcoin private key? </p>

<p>I'm looking to create a web form that can encrypt the form values using only your bitcoin public key. And on the other end when received it can be decrypted with the private key.</p>

<private-key><public-key><encryption><javascript><message>
I have a 100 character text message and I want to encrypt this message with my bitcoin "PUBLIC KEY" and decrypt it with my private key in Javascript
Patoshi パトシ
# I have a 100 character text message and I want to encrypt this message with my bitcoin "PUBLIC KEY" and decrypt it with my private key in Javascript

(Asked by: username_0 on 2018-10-05)

Are there any javascript libraries that can encrypt a 100 character text message using your bitcoin public key, but only be able to decrypt it with your bitcoin private key?

I'm looking to create a web form that can encrypt the form values using only your bitcoin public key. And on the other end when received it can be decrypted with the private key.

**Tags:** private-key, public-key, encryption, javascript, message


---

## 1 answers

### Answer by username_1 on 2018-10-05. Score: 1

You could use something like this [eccrypto](https://github.com/bitchan/eccrypto) (Do your own research on the security of this implementation). Also, doesn't appear to allow compressed public keys. **Update**: It now supports compressed keys as of `v1.1`.

**index.js**

```
var crypto = require("crypto");
var eccrypto = require("eccrypto");

var privateKey = new Buffer("c337ded6f56c07205fb7b391654d7d463c9e0c726869523ae6024c9bec878878", "hex");

//var publicKey = eccrypto.getPublic(privateKey);
var publicKey = new Buffer("04730a151f545f5dcdb1c6d99fb1251f5c70f216f39ba2681bcf10db16bd582e6720bc881d51f25ffbe961df6a0af24a9d39a4db3d86a7f6b3f9bf4eaac0e4006b", "hex");

// Encrypting the message for B.
eccrypto.encrypt(publicKey, Buffer("msg")).then(function(encrypted) {
    console.log('Encrypted message ' + JSON.stringify(encrypted));
  // B decrypting the message.
  eccrypto.decrypt(privateKey, encrypted).then(function(plaintext) {
    console.log("Decrypted message: ", plaintext.toString());
  });
});

```

**Output**

```
$ node index.js
Encrypted message {"iv":{"type":"Buffer","data":[204,13,168,25,80,255,9,233,111,60,165,204,180,126,53,65]},"ephemPublicKey":{"type":"Buffer","data":[4,192,3,65,241,134,65,186,52,52,250,61,208,189,216,167,122,206,156,152,27,173,69,152,37,138,164,5,54,189,227,88,37,243,220,183,22,204,235,37,212,110,207,66,225,244,25,92,69,223,247,175,218,228,134,210,247,190,211,248,239,77,183,21,36]},"ciphertext":{"type":"Buffer","data":[75,104,205,95,93,108,18,50,220,120,164,224,42,214,75,28]},"mac":{"type":"Buffer","data":[63,243,230,143,99,187,246,241,194,10,247,215,188,163,82,98,140,15,186,158,58,207,170,49,230,143,26,17,117,248,195,143]}}
Decrypted message:  msg

```


---

