Last active
March 29, 2018 04:42
-
-
Save sponnet/f91d826dca97321df0e3bb629ba1c621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
performance | |
} = require('perf_hooks'); | |
const EthCrypto = require('eth-crypto'); | |
const identity = EthCrypto.createIdentity(); | |
function randomString(string_length) { | |
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; | |
//var string_length = 8; | |
var randomstring = ''; | |
for (var i = 0; i < string_length; i++) { | |
var rnum = Math.floor(Math.random() * chars.length); | |
randomstring += chars.substring(rnum, rnum + 1); | |
} | |
return randomstring; | |
} | |
const msg = randomString(100000); | |
performance.mark('A'); | |
EthCrypto.encryptWithPublicKey( | |
identity.publicKey, | |
msg // message | |
).then((encrypted) => { | |
performance.mark('B'); | |
performance.measure('A to B', 'A', 'B'); | |
console.log(encrypted); | |
performance.mark('C'); | |
EthCrypto.decryptWithPrivateKey( | |
identity.privateKey, | |
encrypted) | |
.then((message) => { | |
performance.mark('D'); | |
performance.measure('C to D', 'C', 'D'); | |
console.log('message length ' + message.length); | |
console.log('message encrypted. Duration ' + performance.getEntriesByName('A to B')[0].duration + ' ms'); | |
console.log('message decrypted. Duration ' + performance.getEntriesByName('C to D')[0].duration + ' ms'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "encrypttest", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"eth-crypto": "^0.4.0", | |
"perf_hooks": "0.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment