2014-11-06 4 views
9

पैकेज hashids साथ की तरह मिलता है, मैं नंबरों से हैश (और एनकोड y डिकोड) प्राप्त कर सकते हैंतार से हैश, hashids

var Hashids = require("hashids"), 
    hashids = new Hashids("this is my salt", 8); 

var id = hashids.encode(1); 

स्ट्रिंग से प्राप्त हैश के लिए कुछ इसी तरह की पैकेज मौजूद हैं? (एनकोड/डीकोड के साथ)

उत्तर

16
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' 
+0

बफर? मैं इसे कहाँ पा सकता हूँ? धन्यवाद! – Eusthace

+0

https://nodejs.org/api/buffer.html –

+0

क्लाइंट-साइड? ब्राउज़र ... :) – Eusthace