paypro: clientside. start using jsrsasign api correctly.
This commit is contained in:
parent
538c6c32de
commit
059b23f899
|
@ -1,10 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
var Key = require('./Key');
|
||||
var x509 = require('./x509');
|
||||
var RSAKey = x509.RSAKey;
|
||||
var KeyUtil = x509.KEYUTIL;
|
||||
var Signature = x509.crypto.Signature;
|
||||
var KJUR = require('./x509');
|
||||
var assert = require('assert');
|
||||
var PayPro = require('../PayPro');
|
||||
|
||||
|
@ -23,11 +20,13 @@ 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 hexSig = _rsasign_getHexPaddedDigestInfoForString(buf.toString(16), 2048, type);
|
||||
var hexSig = RSAKey.signWith(buf.toString(16), 2048, type);
|
||||
//var size = hexSig.length / 2;
|
||||
//if (size % 2) size++
|
||||
var sig = new Buffer(hexSign, 'hex');
|
||||
var jsrsaSig = KJUR.crypto.Signature({
|
||||
alg: type + 'withRSA',
|
||||
prov: 'cryptojs/jsrsa'
|
||||
});
|
||||
jsrsaSig.initSign(pki_data);
|
||||
jsrsaSig.updateString(buf.toString());
|
||||
var sig = new Buffer(jsrsasig.sign(), 'hex');
|
||||
} else if (pki_type === 'none') {
|
||||
return this;
|
||||
} else {
|
||||
|
@ -52,8 +51,18 @@ PayPro.verify = function() {
|
|||
var pki_data = this.get('pki_data');
|
||||
var buf = this.serializeForSig();
|
||||
var type = pki_type.split('+').toUpperCase();
|
||||
var pubKey = PKCS5PKEY.getRSAKeyFromPublicPKCS8PEM(pki_data);
|
||||
var result = pubKey.verifyPSS(buf, buf.toString(16), type, -1);
|
||||
|
||||
var jsrsaSig = KJUR.crypto.Signature({
|
||||
alg: type + 'withRSA',
|
||||
prov: 'cryptojs/jsrsa'
|
||||
});
|
||||
|
||||
jsrsaSig.initVerifyByCertificatePEM(pki_data);
|
||||
|
||||
jsrsaSig.updateString(buf.toString());
|
||||
|
||||
var result = jsrsaSig.verify(sig.toString(16)); // should be hex
|
||||
|
||||
return result;
|
||||
} else if (pki_type === 'none') {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue