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