forked from Izzzio/BitCoenWallet
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
43 lines (30 loc) · 1.59 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const crypto = require("crypto");
//console.log(crypto.getCurves());
let aliceECDH = crypto.createECDH("secp521r1");
aliceECDH.generateKeys();
let alicePublicKey = aliceECDH.getPublicKey(null, "compressed"),
alicePrivateKey = aliceECDH.getPrivateKey(null, "compressed");
console.log("Alice Public: ", alicePublicKey.length, alicePublicKey.toString("hex"));
console.log("Alice Private:", alicePrivateKey.length, alicePrivateKey.toString("hex"));
let bobECDH = crypto.createECDH("secp521r1");
bobECDH.generateKeys();
let bobPublicKey = bobECDH.getPublicKey(null, "compressed"),
bobPrivateKey = bobECDH.getPrivateKey(null, "compressed");
console.log("Bob Public: ", bobPublicKey.length, bobPublicKey.toString("hex"));
console.log("Bob Private: ", bobPrivateKey.length, bobPrivateKey.toString("hex"));
// On Alice's side
let secret1 = aliceECDH.computeSecret(bobPublicKey);
console.log("Alice Secret: ", secret1.length, secret1.toString("hex"));
// On Bob's side
let secret2 = bobECDH.computeSecret(alicePublicKey);
console.log("Bob Secret: ", secret2.length, secret2.toString("hex"));
console.log('');
let badECDH = crypto.createECDH("secp521r1");
badECDH.generateKeys();
let badPublicKey = badECDH.getPublicKey(null, "compressed"),
badPrivateKey = badECDH.getPrivateKey(null, "compressed");