summaryrefslogtreecommitdiffstats
path: root/node_modules/public-encrypt/withPublic.js
blob: 417a1bf7b3a20f848d6694704db264a01b1f8973 (plain) (blame)
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