Skip to content

Instantly share code, notes, and snippets.

@elegantcoder
Last active August 29, 2015 14:06
Show Gist options
  • Save elegantcoder/245572376d545ee39df2 to your computer and use it in GitHub Desktop.
Save elegantcoder/245572376d545ee39df2 to your computer and use it in GitHub Desktop.
# hashids (https://www.npmjs.org/package/hashids) make to support encrypt/decrypt string, json.
hashIds = new Hashids(secret);
hashIds.encryptString = (str) ->
hashIds.encrypt([].slice.call(new Buffer(str)));
hashIds.decryptString = (encrypted) ->
new Buffer(hashIds.decrypt(encrypted)).toString()
hashIds.encryptJSON = (obj) ->
hashIds.encrypt([].slice.call(new Buffer(JSON.stringify(obj))));
hashIds.decryptJSON = (encrypted) ->
JSON.parse(new Buffer(hashIds.decrypt(encrypted)).toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment