Created
January 18, 2012 19:29
-
-
Save joydrinkstea/1635057 to your computer and use it in GitHub Desktop.
Compute WebSocket Hash
This file contains hidden or 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
| 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