withPublic.js 275 B

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