|
|
@ -256,4 +256,41 @@ PayPro.prototype.sinVerify = function() { |
|
|
|
return Message.verifyWithPubKey(pubkey, buf, sig); |
|
|
|
}; |
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
|
|
|
PayPro.prototype._PEMtoDER = function(pem) { |
|
|
|
return this._PEMtoDERParam(pem); |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype._PEMtoDERParam = function(pem, param) { |
|
|
|
if (Buffer.isBuffer(pem)) { |
|
|
|
pem = pem.toString(); |
|
|
|
} |
|
|
|
var start = new RegExp('(?=-----BEGIN ' + (param || '[^-]+') + '-----)', 'i'); |
|
|
|
var end = new RegExp('^-----END ' + (param || '[^-]+') + '-----$', 'gmi'); |
|
|
|
pem = pem.replace(end, ''); |
|
|
|
var parts = pem.split(start); |
|
|
|
return parts.map(function(part) { |
|
|
|
var type = /-----BEGIN ([^-]+)-----/.exec(part)[1]; |
|
|
|
part = part.replace(/-----BEGIN ([^-]+)-----/g, ''); |
|
|
|
part = part.replace(/\s+/g, ''); |
|
|
|
if (!param || type !== param) return; |
|
|
|
return new Buffer(part, 'base64'); |
|
|
|
}).filter(Boolean); |
|
|
|
}; |
|
|
|
|
|
|
|
PayPro.prototype._DERtoPEM = function(der, type) { |
|
|
|
if (typeof der === 'string') { |
|
|
|
der = new Buffer(der, 'hex'); |
|
|
|
} |
|
|
|
var type = type || 'UNKNOWN'; |
|
|
|
der = der.toString('base64'); |
|
|
|
der = der.replace(/(.{64})/g, '$1\r\n'); |
|
|
|
der = der.replace(/\r\n$/, ''); |
|
|
|
return '' |
|
|
|
+ '-----BEGIN ' + type + '-----\r\n' |
|
|
|
+ der |
|
|
|
+ '\r\n-----END ' + type + '-----\r\n'; |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = PayPro; |
|
|
|