Jua*_*blo 12 hash node.js hashids
使用包哈希,我可以从数字中获取哈希(并编码y解码)
var Hashids = require("hashids"),
hashids = new Hashids("this is my salt", 8);
var id = hashids.encode(1);
Run Code Online (Sandbox Code Playgroud)
存在一些类似的包来从字符串获取哈希?(带编码/解码)
Rom*_*rov 28
var Hashids = require("hashids");
var hashids = new Hashids("this is my salt");
var hex = Buffer('Hello World').toString('hex');
console.log (hex); // '48656c6c6f20576f726c64'
var encoded = hashids.encodeHex(hex);
console.log (encoded); // 'rZ4pPgYxegCarB3eXbg'
var decodedHex = hashids.decodeHex('rZ4pPgYxegCarB3eXbg');
console.log (decodedHex); // '48656c6c6f20576f726c64'
var string = Buffer('48656c6c6f20576f726c64', 'hex').toString('utf8');
console.log (string); // 'Hello World'
Run Code Online (Sandbox Code Playgroud)