프로젝트

일반

사용자정보

통계
| 개정판:

root / HServer / 00.Server / 00.Program / node_modules / random-bytes / README.md

이력 | 보기 | 이력해설 | 다운로드 (2.08 KB)

1 39 HKM
# random-bytes
2
3
[![NPM Version][npm-image]][npm-url]
4
[![NPM Downloads][downloads-image]][downloads-url]
5
[![Node.js Version][node-version-image]][node-version-url]
6
[![Build Status][travis-image]][travis-url]
7
[![Test Coverage][coveralls-image]][coveralls-url]
8
9
Generate strong pseudo-random bytes.
10
11
This module is a simple wrapper around the Node.js core `crypto.randomBytes` API,
12
with the following additions:
13
14
  * A `Promise` interface for environments with promises.
15
  * For Node.js versions that do not wait for the PRNG to be seeded, this module
16
    will wait a bit.
17
18
## Installation
19
20
```sh
21
$ npm install random-bytes
22
```
23
24
## API
25
26
```js
27
var randomBytes = require('random-bytes')
28
```
29
30
### randomBytes(size, callback)
31
32
Generates strong pseudo-random bytes. The `size` argument is a number indicating
33
the number of bytes to generate.
34
35
```js
36
randomBytes(12, function (error, bytes) {
37
  if (error) throw error
38
  // do something with the bytes
39
})
40
```
41
42
### randomBytes(size)
43
44
Generates strong pseudo-random bytes and return a `Promise`. The `size` argument is
45
a number indicating the number of bytes to generate.
46
47
**Note**: To use promises in Node.js _prior to 0.12_, promises must be
48
"polyfilled" using `global.Promise = require('bluebird')`.
49
50
```js
51
randomBytes(18).then(function (string) {
52
  // do something with the string
53
})
54
```
55
56
### randomBytes.sync(size)
57
58
A synchronous version of above.
59
60
```js
61
var bytes = randomBytes.sync(18)
62
```
63
64
## License
65
66
[MIT](LICENSE)
67
68
[npm-image]: https://img.shields.io/npm/v/random-bytes.svg
69
[npm-url]: https://npmjs.org/package/random-bytes
70
[node-version-image]: https://img.shields.io/node/v/random-bytes.svg
71
[node-version-url]: http://nodejs.org/download/
72
[travis-image]: https://img.shields.io/travis/crypto-utils/random-bytes/master.svg
73
[travis-url]: https://travis-ci.org/crypto-utils/random-bytes
74
[coveralls-image]: https://img.shields.io/coveralls/crypto-utils/random-bytes/master.svg
75
[coveralls-url]: https://coveralls.io/r/crypto-utils/random-bytes?branch=master
76
[downloads-image]: https://img.shields.io/npm/dm/random-bytes.svg
77
[downloads-url]: https://npmjs.org/package/random-bytes