Skip to content

Signed ObjectId string generation for secure, URL-safe codes

License

Notifications You must be signed in to change notification settings

edappy/signed-objectid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

signed-objectid

Circle CI

Generate URL-safe signed codes based on 24-character hex string (like Mongo ObjectID)

  • Requires Node 4+ (ES2015)

Usage

  • The secret used to sign keys can be specified as a string in the environment variable SIGNED_CODE_SECRET
  • In the absence of SIGNED_CODE_SECRET, a fallback secret can be provided to the module function
  • Only 24-character hex strings are supported. Anything else will throw an Error
  • Any invalid or unverifiable input provided to unsign will return a null
const signedObjectId = require('signed-objectid')('DevTestSecret')
console.log(signedObjectId.sign('507f1f77bcf86cd799439011'))

// -> w9-jeWfZ8hayp94dM-euVr351i1KQMHxt6mLTEfFRiXRA5QZeNb4z7df8HU

console.log(signedObjectId.unsign('w9-jeWfZ8hayp94dM-euVr351i1KQMHxt6mLTEfFRiXRA5QZeNb4z7df8HU'))

// -> 507f1f77bcf86cd799439011

About

Signed ObjectId string generation for secure, URL-safe codes

Resources

License

Stars

Watchers

Forks

Packages

No packages published