UNPKG

@incubatorit/node-redsys-api

Version:

Node.js Redsys api implementation with new the key-hashed message authentication code (HMAC) SHA256 for the virtual payment gateway integration. This is a node.js port of the PHP API provided by [Redsys](http://www.redsys.es/)

22 lines (19 loc) 553 B
function zeroPad(buf, blocksize) { const buffer = typeof buf === "string" ? Buffer.from(buf, "utf8") : buf; const pad = Buffer.alloc((blocksize - (buffer.length % blocksize)) % blocksize, 0); return Buffer.concat([buffer, pad]); } function zeroUnpad(buf, blocksize) { let lastIndex = buf.length; while (lastIndex >= 0 && lastIndex > buf.length - blocksize - 1) { lastIndex -= 1; if (buf[lastIndex] !== 0) { break; } } return buf.slice(0, lastIndex + 1).toString("utf8"); } module.exports = { zeroPad, zeroUnpad, };