UNPKG

1.34 kBMarkdownView Raw
1---
2title: ECIES
3description: Uses ECIES symmetric key negotiation from public keys to encrypt arbitrarily long data streams.
4---
5# ECIES
6
7## Description
8
9Bitcore implements [Elliptic Curve Integrated Encryption Scheme (ECIES)](http://en.wikipedia.org/wiki/Integrated_Encryption_Scheme), which is a public key encryption system that performs bulk encryption on data using a symmetric cipher and a random key.
10
11For more information refer to the [bitcore-ecies](https://github.com/bitpay/bitcore-ecies) github repo.
12
13## Installation
14
15ECIES is implemented as a separate module and you must add it to your dependencies:
16
17For node projects:
18```bash
19npm install bitcore-ecies --save
20```
21
22For client-side projects:
23```bash
24bower install bitcore-ecies --save
25```
26
27## Example
28
29```javascript
30var bitcore = require('bitcore-lib');
31var ECIES = require('bitcore-ecies');
32
33var alicePrivateKey = new bitcore.PrivateKey();
34var bobPrivateKey = new bitcore.PrivateKey();
35
36var data = new Buffer('The is a raw data example');
37
38// Encrypt data
39var cypher1 = ECIES.privateKey(alicePrivateKey).publicKey(bobPrivateKey.publicKey);
40var encrypted = cypher1.encrypt(data);
41
42// Decrypt data
43var cypher2 = ECIES.privateKey(bobPrivateKey).publicKey(alicePrivateKey.publicKey);
44var decrypted = cypher2.decrypt(encrypted);
45
46assert(data.toString(), decrypted.toString());
47```