Created
December 11, 2020 05:50
-
-
Save teiikushi07/40fa141237a763b8cf30d8c1095eb1c8 to your computer and use it in GitHub Desktop.
ED25519 Node.js Sample
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 crypto = require('crypto'); | |
const fs = require('fs'); | |
const data = fs.readFileSync('./data.txt'); | |
const key = fs.readFileSync('./private_key.pem'); | |
const pub = fs.readFileSync('./public_key.pem'); | |
console.log('data:', data); | |
console.log('key:', key.toString('base64')); | |
const sign = crypto.sign(null, data, key); | |
console.log('sign:', sign.toString('base64'), sign.toString('base64').length); | |
console.log('verified:', crypto.verify(null, data, pub, sign)); | |
const now = Date.now(); | |
for (let i = 0; i < 10000; i++) { | |
crypto.verify(null, data, pub, sign); | |
} | |
console.log('It takes time to verify 10,000 times:', (Date.now() - now) / 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment