withPublic.js 275 Bytes Raw Blame History Permalink 1 2 3 4 5 6 7 8 9 10 11 12 var BN = require('bn.js') var Buffer = require('safe-buffer').Buffer function withPublic (paddedMsg, key) { return Buffer.from(paddedMsg .toRed(BN.mont(key.modulus)) .redPow(new BN(key.publicExponent)) .fromRed() .toArray()) } module.exports = withPublic