Created
January 26, 2011 15:25
-
-
Save kurokikaze/796837 to your computer and use it in GitHub Desktop.
Websocket 76 opening handshake demo for Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var key1 = 155712099; | |
//var key1 = 829309203; | |
var key2 = 173347027; | |
// var key2 = 259970620; | |
//var sign = '^n:ds[4U'; | |
var sign = 'Tm[K T2u'; | |
function intToBigEndian(intstr){ | |
var st = new Buffer(4); | |
console.log('BigEndian ' + intstr); | |
st[0] = intstr >>> 24; | |
console.log('0 : ' + st[0]); | |
st[1] = intstr >>> 16; | |
console.log('1 : ' + st[1]); | |
st[2] = intstr >>> 8; | |
console.log('2 : ' + st[2]); | |
st[3] = intstr >>> 0; | |
console.log('3 : ' + st[3]); | |
return st; | |
} | |
var n1 = intToBigEndian(key1); | |
var n2 = intToBigEndian(key2); | |
var n3 = Buffer(sign, 'utf8'); | |
var hash = crypto.createHash('md5'); | |
var buf = n1 + n2 + n3; | |
console.log('Resulting answer length: ' + buf.length); | |
//console.log('Buffer itself: ' + buf.toString('ascii')); | |
hash.update(n1); | |
hash.update(n2); | |
hash.update(n3); | |
//hash.update(n2); | |
//hash.update(n3); | |
console.log(hash.digest().toString('ascii')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment