Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.28 KB

README.MD

File metadata and controls

44 lines (33 loc) · 1.28 KB

SECURE JSON WEB TOKEN LIBRARY

Secure your payloads by adding an extra layer of encryption to your applications, especially when sending data across the internet.

Install

npm install securejwt

Usage

sjwt.setKeyPath(_path_)

Sets the location to store sjwt key and (re)generates key.

  • _path_: <string>

sjwt.generateJWT(payload,fingerprint)

Returns JsonWebToken with aes256 encrypted payload. See JsonWebToken

  • payload: <Object>|<Primitive>|<Buffer>
  • fingerprint: <string>

sjwt.retrieveJWT(JWTString,fingerprint)

Returns decrypted payload of JWTString

  • JWTString: <string>
  • fingerprint: <string>

Full Example

var sjwt = require("securejwt"); // require module

/* Variables */
var keyPath = "~/jwtkeys"; // define keypath
var payload = { "message" : "hello" }; // define payload
var fingerprint = "myFingerPrint"; // define fingerprint

/* Methods */
sjwt.setKeyPath(keyPath); // set key path
var secureToken = sjwt.generateJWT(payload, fingerprint); // generate secureToken
var payload = sjwt.retrieveJWT(secureToken,fingerprint); // decrypt payload

/* Inspection */
console.log(secureToken); // output secureToken to inspect payload
console.log(payload.message); // access payload data