From 722a10f9653b8d5dd292c3ee03f7aa691fbe2c72 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 16 Jul 2014 15:08:02 -0700 Subject: [PATCH] paypro: fix encodings with jsrsasign. --- lib/browser/PayPro.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/browser/PayPro.js b/lib/browser/PayPro.js index 10a7697..52e98fb 100644 --- a/lib/browser/PayPro.js +++ b/lib/browser/PayPro.js @@ -20,12 +20,12 @@ PayPro.sign = function(key) { var pki_data = this.get('pki_data'); // contains one or more x509 certs var type = pki_type.split('+').toUpperCase(); var buf = this.serializeForSig(); - var jsrsaSig = KJUR.crypto.Signature({ + var jsrsaSig = new KJUR.crypto.Signature({ alg: type + 'withRSA', prov: 'cryptojs/jsrsa' }); jsrsaSig.initSign(pki_data); - jsrsaSig.updateString(buf.toString()); + jsrsaSig.updateHex(buf.toString('hex')); var sig = new Buffer(jsrsasig.sign(), 'hex'); } else if (pki_type === 'none') { return this; @@ -33,7 +33,6 @@ PayPro.sign = function(key) { throw new Error('Unsupported pki_type'); } - this.set('signature', sig); return this; }; @@ -52,16 +51,16 @@ PayPro.verify = function() { var buf = this.serializeForSig(); var type = pki_type.split('+').toUpperCase(); - var jsrsaSig = KJUR.crypto.Signature({ + var jsrsaSig = new KJUR.crypto.Signature({ alg: type + 'withRSA', prov: 'cryptojs/jsrsa' }); jsrsaSig.initVerifyByCertificatePEM(pki_data); - jsrsaSig.updateString(buf.toString()); + jsrsaSig.updateHex(buf.toString('hex')); - var result = jsrsaSig.verify(sig.toString(16)); // should be hex + var result = jsrsaSig.verify(sig.toString('hex')); return result; } else if (pki_type === 'none') {