Modular package of Tom Wu's JavaScript implementation of arbitrary-precision integer arithmetic.
Licensed under the BSD license.
- Modular
- Unit tested
- Node compatible
- Top-level module preventing global scope pollution in the browser
- JSHint compliance
JSBN is available directly from GitHub:
npm install timkurvers/jsbn.git
const jsbn = require('jsbn');
jsbn.Base64.fromHex('4a53424e') // 'SlNCTg=='
jsbn.Base64.toHex('SlNCTg==') // '4a53424e'
jsbn.Base64.toByteArray('SlNCTg==') // [74, 83, 66, 78]
const encrypter = new jsbn.Crypto.RC4();
const key = [1, 3, 3, 7];
encrypter.init(key);
const data = [1, 2, 3];
encrypter.encrypt(data);
jsbn.Crypto.SHA1.fromArray([97]) // [134, 247, 228, ..., 103, 184]
jsbn.Crypto.SHA1.fromString('a') // '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
jsbn.Crypto.SHA1.HMAC.fromStrings('', '') // 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d'
jsbn.Crypto.SHA1.HMAC.fromArrays([], []) // [251, 219, 29, ..., 14, 29]
const a = jsbn.Math.BigInteger.fromInt(25);
const b = new jsbn.Math.BigInteger('1002', 10);
a.add(b).intValue() // 1027