https://github.com/timkurvers/jsbn
Modular package of Tom Wu's JavaScript implementation of arbitrary-precision integer arithmetic
https://github.com/timkurvers/jsbn
Last synced: 4 months ago
JSON representation
Modular package of Tom Wu's JavaScript implementation of arbitrary-precision integer arithmetic
- Host: GitHub
- URL: https://github.com/timkurvers/jsbn
- Owner: timkurvers
- License: other
- Created: 2014-10-28T19:47:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-03T09:08:17.000Z (over 7 years ago)
- Last Synced: 2025-01-01T04:16:29.501Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# JSBN
[](https://github.com/timkurvers/jsbn/tree/v1.4.0)
[](https://travis-ci.org/timkurvers/jsbn)
[](https://codeclimate.com/github/timkurvers/jsbn)
[](https://codeclimate.com/github/timkurvers/jsbn)
[](https://snyk.io/test/github/timkurvers/jsbn)Modular package of [Tom Wu's JavaScript implementation of arbitrary-precision integer arithmetic](http://www-cs-students.stanford.edu/~tjw/jsbn/).
Licensed under the [**BSD** license](LICENSE.md).
## Features
* Modular
* Unit tested
* Node compatible
* Top-level module preventing global scope pollution in the browser
* JSHint compliance## Installation
JSBN is available directly from GitHub:
```shell
npm install timkurvers/jsbn.git
```## Usage & API
```javascript
const jsbn = require('jsbn');
```### Base64
```javascript
jsbn.Base64.fromHex('4a53424e') // 'SlNCTg=='
jsbn.Base64.toHex('SlNCTg==') // '4a53424e'
jsbn.Base64.toByteArray('SlNCTg==') // [74, 83, 66, 78]
```### Crypto
#### RC4
```javascript
const encrypter = new jsbn.Crypto.RC4();
const key = [1, 3, 3, 7];
encrypter.init(key);const data = [1, 2, 3];
encrypter.encrypt(data);
```#### SHA1
```javascript
jsbn.Crypto.SHA1.fromArray([97]) // [134, 247, 228, ..., 103, 184]
jsbn.Crypto.SHA1.fromString('a') // '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
```##### HMAC
```javascript
jsbn.Crypto.SHA1.HMAC.fromStrings('', '') // 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d'
jsbn.Crypto.SHA1.HMAC.fromArrays([], []) // [251, 219, 29, ..., 14, 29]
```### Math
#### BigInteger
```javascript
const a = jsbn.Math.BigInteger.fromInt(25);
const b = new jsbn.Math.BigInteger('1002', 10);a.add(b).intValue() // 1027
```