Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: bardi.harborow on May 28, 2014, 12:26:00 AM



Title: [ANN] Node.js ECIES. Encrypt messages to Bitcoin Addresses!
Post by: bardi.harborow on May 28, 2014, 12:26:00 AM
Hey BitcoinTalk!

Just thought I'd show you all my latest invention. Node-ECIES is a Node.js implementation of ECIES, a little known elliptic curve encryption system using ECDH and a Symmetric Cipher (not sure which one, maybe AES). What that means in English, is that given a Bitcoin address' public key, you can encrypt messages to it. Now, this is not all my work, all I did was put a wrapper around node-cryptopp, which in turn is a set of bindings for Crypto++. What I did do is figure out how to use node-cryptopp to do ECIES. Note that you can't send messages to bitcoin addresses, only to public keys, which are available if the user has sent bitcoins from their address.

You can query for the public key by doing: https://blockchain.info/q/pubkeyaddr/1Bardi4eoUvJomBEtVoxPcP8VK26E3Ayxn (https://blockchain.info/q/pubkeyaddr/1Bardi4eoUvJomBEtVoxPcP8VK26E3Ayxn)

Usage:
Code:
var bitcoin = require('bitcoinjs-lib'),
     ecies = require('ecies');
var text = 'Secret ECIES Test Message!';
/* sha256('correct horse battery staple') */
var publicKey = '0478d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455';
var privateKey = bitcoin.ECKey('5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS').toHex();
var cipherText = ecies.encrypt(text, publicKey, 'secp256k1');
var decryptedText = ecies.decrypt(cipherText, privateKey, 'secp256k1');
console.log(text, '->', cipherText, '->', decryptedText);

Install:
Code:
npm install ecies

Source Code (https://github.com/bardiharborow/node-ecies)
NPM (https://www.npmjs.org/package/ecies)

And of course, where would I be without a selfish request for donations. Coins sent to the address in the signature pay for me to create implementations in different languages.

Have a nice day.


Title: Re: [ANN] Node.js ECIES. Encrypt messages to Bitcoin Addresses!
Post by: ThePurplePlanet on May 28, 2014, 02:22:34 AM
Maybe it is better to post it at Bitcoin dev discussion or  projects discussion


Title: Re: [ANN] Node.js ECIES. Encrypt messages to Bitcoin Addresses!
Post by: str4wm4n on May 28, 2014, 05:19:44 AM
awesome, I always wondered if this was possible!