# secure-random-string

> Generates a secure random string with a given length

Latest version **1.1.4** (published 2024-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install secure-random-string
pnpm add secure-random-string
yarn add secure-random-string
bun add secure-random-string
```

## Health

**Score 33/100 (F)** — status: maintenance-mode.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2024-09-26 |
| First published | 2015-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/secure-random-string) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Simon Santoro |
| Maintainers | s2 |
| Keywords | crypto, cryptography, secure, random, string, token |

## Links

- npm: https://www.npmjs.com/package/secure-random-string
- Repository: https://github.com/5im-0n/securerandomstring
- Issues: https://github.com/5im-0n/securerandomstring/issues
- npm.io page: https://npm.io/package/secure-random-string

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2024-09-26
- 1.1.3 — 2020-04-08
- 1.1.2 — 2019-07-13
- 1.1.0 — 2017-11-26
- 1.0.0 — 2015-08-27
- 0.1.0 — 2015-08-21
- 0.0.2 — 2015-04-25

## README

# secure-random-string

Node.js module that generates a cryptographically secure random string with a given length

## Usage

```javascript
var srs = require('secure-random-string');
```

### Default behavior: Generate a random Base64 encoded string 32 characters long.

This may include alphanumeric characters as well as the following characters: +, /, =.

```javascript
// Sync
var result = srs();

// Async
srs(function(err, sr) {
	console.log(sr);
});

```

### Options: length

Optionally, you can specify a 'length' option to specify a length.

```javascript
// sync
var result = srs({length: 256});

// async
srs({length: 256}, function(err, sr) {
	console.log(sr);
});
```
### Options: alphanumeric

Optionally, you can specify a 'alphanumeric' option to get a alphanumerical chars only.

```javascript
// sync
var result = srs({alphanumeric: true});

// async
srs({alphanumeric: true}, function(err, sr) {
	console.log(sr);
});
```
## Error handling


An error is possible if there is not enough accumulated entropy to generate cryptographically strong data. In other words, this will not block even if all entropy sources are drained. Note that the sync API throws an exception, while
the async API returns the error to the callback.

## Author

 [Simon Santoro](https://github.com/S2-)

## Contributors

 [Mark Stosberg](https://github.com/markstos)  
 [Sandro Gomez](https://github.com/mrsangrin)

## License

[MIT](https://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/secure-random-string · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
