I got this data from a user: <Buffer 81 8b 4d 25 17 97 05 40 7b fb 22 05 40 f8 3f 49 73> Code (markup): I guess it was sha1 encoding. How do I turn it to something like this on the browser: 'Hello World' Code (markup): I tried this it isn't work: buf = new Buffer(str.length); for (var i = 0; i < str.length ; i++) { buf[i] = str.charCodeAt(i); } console.log(buf); Code (markup): I know it needs a key. I got the key. Any idea how to decode it? Thanks,
Without knowing how it was encoded that's hard to say -- if it's a hash then it's SUPPOSED to be irreversible... though that string is obviously a set of hex pairs... so if you extracted just the hex code part of the string... var testString = '81 8b 4d 25 17 97 05 40 7b fb 22 05 40 f8 3f 49 73', testArray = testString.split(' '), result = ''; for (var i = 0; i < testArray.length; i++) { var b = parseInt(testArray[i], 16); // parse bytes here } Code (markup): That at least turns the hexadecimal bytes into decimal -- But without knowing the encoding or if said encoding is even supposed to be reversible? Remember, hashing algorithms are supposed to be irreversible, so short of building a rainbow table (or using an existing one)... Really though if it's SHA1 encoded as hexadecimal, you're going to need a proper SHA1 parser, which is NOT a simple small bit of code... and certainly NOT something one should even be screwing with client side in JS.
Thanks for quick reply. I'm able mange to solve it with your guide. Here's how I did it. http://jalaj.net/blog/2012/09/13/hex-to-from-ascii-in-javascript/ I'm not sure if it encoded as SHA1. All I know is the data is a buffer and I have to decoded it. It comes with http header. I wonder if every data transfer have to come with headers. According to the Wikipedia: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields There are up to 8190 bytes of header for single request.