New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

uuid-key-generator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

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

0.1.0
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

UUID Key Generator

NPM Version Build Status Coverage Status Dependency Status devDependency Status

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 specified bit-size of 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 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

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.

FAQs

Package last updated on 23 Aug 2015

Did you know?

Socket

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