Socket
Socket
Sign inDemoInstall

uuid-key-generator

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    uuid-key-generator

Generates random keys with custom size and base-encoding using the RFC4122 v4 UUID algorithm


Version published
Weekly downloads
12
Maintainers
1
Install size
45.3 kB
Created
Weekly downloads
 

Readme

Source

UUID Key Generator

This module has been deprecated in favour of uuid-token-generator. Please note that there are breaking changes when upgrading to uuid-token-generator.
However, you should probably use uid-generator instead since it allows for more customization in the tokens it generates and does not produce overlapping UIDs.

Provides a class that generates random keys with custom size and base-encoding using the RFC4122 v4 UUID algorithm. Generated keys are strings that are guaranteed to always be the same length, depending on the bit-size specified for the key.

Great for generating things like API keys and compact IDs.

Installation

npm install uuid-key-generator --save

Usage

var KeyGenerator = require('uuid-key-generator');

var keygen = new KeyGenerator(); // Default is a 128-bit key encoded in base58
keygen.generateKey();
// -> '4QhmRwHwwrgFqXULXNtx4d'

var keygen2 = new KeyGenerator(256, KeyGenerator.BASE62);
keygen2.generateKey();
// -> 'x6GCX3aq9hIT8gjhvO96ObYj0W5HBVTsj64eqCuVc5X'

API

new KeyGenerator([bitSize][, baseEncoding]) ⇒ Object

Creates a new KeyGenerator instance that generates bitSize-bit keys encoded using the characters in baseEncoding.

ParamDefaultTypeDescription
[bitSize]128numberThe size of the key to generate in bits. Must be a multiple of 128.
[baseEncoding]KeyGenerator.BASE58stringOne of the KeyGenerator.BASE## constants or a custom string of characters to use to encode the key.

Example

new KeyGenerator();
new KeyGenerator(256);
new KeyGenerator(KeyGenerator.BASE36);
new KeyGenerator(512, KeyGenerator.BASE62);
new KeyGenerator('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/'); // Custom encoding (base64)

KeyGenerator.BASE16 : String

0123456789abcdef

KeyGenerator.BASE36 : String

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

KeyGenerator.BASE58 : String

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

KeyGenerator.BASE62 : String

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

KeyGenerator.BASE71 : String

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!'()*-._~

(all ASCII characters that are not escaped by encodeURIComponent())


keygen.generateKey() ⇒ String

Generates a random key.

Returns: String - A random key that is always keygen.keyLength characters long.

Example

var keygen = new KeyGenerator();
keygen.generateKey();
// -> 'vf5NrETkUKCa6FhkyRSazD'

(readonly) keygen.bitSize : Number

The size of the key that will be generated in bits (the bitSize value passed to the KeyGenerator constructor).

(readonly) keygen.baseEncoding : String

The set of characters used to encode the key (the baseEncoding value passed to the KeyGenerator constructor).

(readonly) keygen.base : Number

The base of the key that will be generated (which is the number of characters in the baseEncoding).

(readonly) keygen.keyLength : Number

The length of the key that will be generated. The generated key will always be this length.
Calculated as such: keyLength = Math.ceil(bitSize / Math.log2(base))

Keywords

FAQs

Last updated on 09 Dec 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc