From 3995f96896c552feb8ddae3a263e61b6ee138f99 Mon Sep 17 00:00:00 2001 From: Simon El Nahas Christensen Date: Sun, 21 Jul 2019 14:14:36 +0200 Subject: [PATCH] 08 solution proposal taking arguments --- problems/09.md | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/problems/09.md b/problems/09.md index f4f7af0..e09cecc 100644 --- a/problems/09.md +++ b/problems/09.md @@ -5,24 +5,44 @@ ```js // sign.js +// usage: +// node sign.js "message" +// signature and publickey will be in hex format var sodium = require('sodium-native') +const args = process.argv.slice(2) +const messageString = args[0] -var publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES) -var secretKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES) -sodium.crypto_sign_keypair(publicKey, secretKey) - -var message = Buffer.from('Hello world!') +const messageBuffer = Buffer.from(messageString) +var publickey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES) +var secretkey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES) var signature = Buffer.alloc(sodium.crypto_sign_BYTES) -sodium.crypto_sign_detached(signature, message, secretKey) +sodium.crypto_sign_keypair(publickey, secretkey) + +sodium.crypto_sign_detached(signature, messageBuffer, secretkey) -console.log('Public key: ' + publicKey.toString('hex')) -console.log('Message: ' + message.toString()) console.log('Signature: ' + signature.toString('hex')) +console.log('Message: "' + messageBuffer.toString()+'"') +console.log('Public key: ' + publickey.toString('hex')) ``` ```js // verify.js +// usage: +// node verify.js signature "message" publickey +// signature and publickey should be in hex format + +var sodium = require('sodium-native') +const args = process.argv.slice(2) +var publickey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES) +var signature = Buffer.alloc(sodium.crypto_sign_BYTES) + +signature = Buffer.from(args[0],'hex') +message = Buffer.from(args[1]) +publickey = Buffer.from(args[2],'hex') + +const isValid = sodium.crypto_sign_verify_detached(signature,message,publickey) +console.log("isValid: "+isValid) ```