Skip to content

Instantly share code, notes, and snippets.

@joydrinkstea
Created January 18, 2012 19:29
Show Gist options
  • Select an option

  • Save joydrinkstea/1635057 to your computer and use it in GitHub Desktop.

Select an option

Save joydrinkstea/1635057 to your computer and use it in GitHub Desktop.
Compute WebSocket Hash
public String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey)
{
const String MagicKEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
String secWebSocketAccept = String.Empty;
// 1. Combine the request Sec-WebSocket-Key with magic key.
String ret = secWebSocketKey + MagicKEY;
// 2. Compute the SHA1 hash
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));
// 3. Base64 encode the hash
secWebSocketAccept = Convert.ToBase64String(sha1Hash);
return secWebSocketAccept;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment