From 09c15b9d1a1d2a0d321f1f64eccc95fdd2e92262 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 1 Aug 2016 04:12:01 -0400 Subject: [PATCH] generateSignatureJwk works with both ursa and forge :) --- node.js | 10 +++++++++- tests/generate-sig.js | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/node.js b/node.js index 2e9f31c..142b18e 100644 --- a/node.js +++ b/node.js @@ -110,7 +110,15 @@ function create(deps) { }; RSA._forgeGenerateSig = function (keypair, sha256Buf) { var forge = require('node-forge'); - var md = forge.util.createBuffer(sha256Buf.toString('binary'), 'binary'); + var bufF = forge.util.createBuffer(sha256Buf.toString('binary'), 'binary'); + var md = { + algorithm: 'sha256' + , blockLength: 64 + , digestLength: 20 + , digest: function () { + return bufF; + } + }; var sigF = keypair._forge.sign(md); var sig64 = RSA.utils.toWebsafeBase64( new Buffer(forge.util.bytesToHex(sigF), "hex").toString('base64') diff --git a/tests/generate-sig.js b/tests/generate-sig.js index cddcb82..048d21e 100644 --- a/tests/generate-sig.js +++ b/tests/generate-sig.js @@ -16,7 +16,8 @@ var keypair = { } }; -var result = { +/* +var ursaResult = { "header": { "alg": "RS256", "jwk": { @@ -29,6 +30,20 @@ var result = { "payload": "JLzF1NBNCV3kfbJ5sFaFyX94fJuL2H-IzaoBN-ciiHk", "signature": "Wb2al5SDyh5gjmkV79MK9m3sfNBBPjntSKor-34BBoGwr6n8qEnBmqB1Y4zbo-5rmvsoPmJsnRlP_hRiUY86zSAQyfbisTGrGBl0IQ7ditpkfYVm0rBWJ8WnYNqYNp8K3qcD7NW72tsy-XoWEjNlz4lWJeRdEG2Nt4CJgnREH4Y" }; +var forgeResult = { + "header": { + "alg": "RS256", + "jwk": { + "kty": "RSA", + "n": "AMJubTfOtAarnJytLE8fhNsEI8wnpjRvBXGK/Kp0675J10ORzxyMLqzIZF3tcrUkKBrtdc79u4X0GocDUgukpfkY+2UPUS/GxehUYbYrJYWOLkoJWzxn7wfoo9X1JgvBMY6wHQnTKvnzZdkom2FMhGxkLaEUGDSfsNznTTZNBBg9", + "e": "AQAB" + } + }, + "protected": "eyJub25jZSI6IjhlZjU2MjRmNWVjOWQzZWYifQ", + "payload": "JLzF1NBNCV3kfbJ5sFaFyX94fJuL2H-IzaoBN-ciiHk", + "signature": "Wb2al5SDyh5gjmkV79MK9m3sfNBBPjntSKor-34BBoGwr6n8qEnBmqB1Y4zbo-5rmvsoPmJsnRlP_hRiUY86zSAQyfbisTGrGBl0IQ7ditpkfYVm0rBWJ8WnYNqYNp8K3qcD7NW72tsy-XoWEjNlz4lWJeRdEG2Nt4CJgnREH4Y" +}; +*/ var jws = RSA.generateSignatureJwk( keypair