Uploaded: 23 Jun, 2011
Previous uploads by this submitter: 0

Author: Mastermosley

Downloads: 33

.NET 4.0

For anyone experimenting with Websockets this program will calculate the MD5 Challenge based on Sec-WebSocket-Key1, Sec-webSocket-Key2, and Key3 which is the last 8 bytes after the first 0x0D, 0x0A, 0x0D, 0x0A.

Here is the source of the main function (in C#)
Note the input into the function is based on the integers after the division.

public byte[] getHandshake(uint firstKey, uint secondKey, byte[] last8)
uint BE_key1 = 0; uint BE_key2 = 0;
byte[] finalbyte;
if (BitConverter.IsLittleEndian)
byte[] temp = BitConverter.GetBytes(firstKey);
BE_key1 = BitConverter.ToUInt32(temp, 0);

byte[] temp2 = BitConverter.GetBytes(secondKey);
BE_key2 = BitConverter.ToUInt32(temp2, 0);

//Cocatenate bytes together
finalbyte = new byte[temp.Length + temp2.Length + last8.Length];
System.Buffer.BlockCopy(temp, 0, finalbyte, 0, temp.Length);
System.Buffer.BlockCopy(temp2, 0, finalbyte, temp.Length, temp2.Length);
System.Buffer.BlockCopy(last8, 0, finalbyte, (temp.Length) + (temp2.Length), last8.Length);

MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
byte[] output = x.ComputeHash(finalbyte);
return output;
return null;