-
-
Save levex/6a22f20eea40e0eb337a02ba906f79d8 to your computer and use it in GitHub Desktop.
deno crypto ECDH tester
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 { | |
createECDH, | |
getCurves, | |
} = await import('node:crypto'); | |
let isThisDeno = typeof Deno !== "undefined"; | |
let curves = getCurves(); | |
for (let curve of curves) { | |
console.log(curve); | |
console.log("========="); | |
console.log(""); | |
// Generate Alice's keys... | |
let alice = createECDH(curve); | |
let aliceKey = alice.generateKeys(); | |
console.log("aliceKey ", aliceKey.toString('hex')); | |
// Generate Bob's keys... | |
let bob = createECDH(curve); | |
let bobKey = bob.generateKeys(); | |
console.log("bobKey ", bobKey.toString('hex')); | |
// Exchange and generate the secret... | |
let aliceSecret = alice.computeSecret(bobKey); | |
let bobSecret = bob.computeSecret(aliceKey); | |
// OK | |
console.log('aliceECDHSecret ', aliceSecret.toString('hex')); | |
console.log('bobECDHSecret ', bobSecret.toString('hex')); | |
console.log('publicKeySize ', aliceKey.length); | |
if (!isThisDeno) | |
console.log('privateKeySize ', alice.getPrivateKey().length); | |
console.log('sharedSecretSize ', aliceSecret.length); | |
console.log(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nit: