Skip to content

Commit

Permalink
Merge pull request #372 from ryanxcharles/feature/ECIES-example
Browse files Browse the repository at this point in the history
add ECIES example
  • Loading branch information
Ryan X. Charles committed Jun 6, 2014
2 parents 6aef44e + 261a94d commit ddd52c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/ECIES.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var run = function() {
bitcore = typeof (bitcore) === 'undefined' ? require('../bitcore') : bitcore;

console.log('ECIES: Elliptic Curve Integrated Encryption Scheme');
console.log('A way of encrypting with a public key and decrypting with a private key.');

var key = bitcore.Key.generateSync();
console.log('Private key: ' + key.private.toString('hex'));
console.log('Public key: ' + key.public.toString('hex'));

var message = new Buffer('This is a message to be encrypted');
console.log('Message: "' + message.toString() + '"');

var encrypted = bitcore.ECIES.encrypt(key.public, message);
console.log('Encrypted (with public key): ' + encrypted.toString('hex'));

var decrypted = bitcore.ECIES.decrypt(key.private, encrypted);
console.log('Decrypted (with private key): "' + decrypted.toString() + '"');
};


// This is just for browser & mocha compatibility
if (typeof module !== 'undefined') {
module.exports.run = run;
if (require.main === module) {
run();
}
} else {
run();
}
1 change: 1 addition & 0 deletions test/test.examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var unmute = require('./mute').unmute;

var examples = [
'Address',
'ECIES',
'HierarchicalKey',
'PeerManager',
'Rpc',
Expand Down

0 comments on commit ddd52c2

Please sign in to comment.