Skip to content

Instantly share code, notes, and snippets.

@kurokikaze

kurokikaze/test.js

Created Jan 26, 2011
Embed
What would you like to do?
Websocket 76 opening handshake demo for Node.js
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
You can’t perform that action at this time.