Skip to content

Instantly share code, notes, and snippets.

@maraoz
Created January 15, 2015 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maraoz/43ab4c787c46f5caa490 to your computer and use it in GitHub Desktop.
Save maraoz/43ab4c787c46f5caa490 to your computer and use it in GitHub Desktop.
bitcore browser submodule example usage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bitcore ECIES browser usage</title>
<script src="bitcore.min.js"></script>
<script src="bitcore-ecies.min.js"></script>
</head>
<body>
<script type="text/javascript">
var bitcore = require('bitcore');
var ECIES = require('bitcore-ecies');
var PrivateKey = bitcore.PrivateKey;
var alice = new PrivateKey();
var bob = new PrivateKey();
var message = 'a secret message!1!!';
var encryptor = new ECIES()
.privateKey(alice)
.publicKey(bob.toPublicKey());
var encrypted = encryptor.encrypt(message);
console.log(encrypted.toString());
var decryptor = new ECIES()
.privateKey(bob)
.publicKey(alice.toPublicKey());
var decrypted = decryptor.decrypt(encrypted);
console.log(decrypted.toString());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment