title: How can I get the sha1 hash of a string in node.js?
body: <p>I'm trying to create a websocket server written in node.js</p>
  <p>To get the server to work I need to get the SHA1 hash of a string.</p>
  <p>What I have to do is explained in <a href="https://datatracker.ietf.org/doc/html/draft-ietf-hybi-thewebsocketprotocol-10#page-36" rel="noreferrer">Section 5.2.2 page 35 of the docs</a>.</p>
  <blockquote>
  <p>NOTE: As an example, if the value of the <code>&quot;Sec-WebSocket-Key&quot;</code>
  header in the client's handshake were <code>&quot;dGhlIHNhbXBsZSBub25jZQ==&quot;</code>, the server would append thestring <code>&quot;258EAFA5-E914-47DA-95CA-C5AB0DC85B11&quot;</code> to form the
  string <code>&quot;dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11&quot;</code>.  The server would then take the SHA-1 hash of this string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea.  This value is then base64-encoded, to give the value <code>&quot;s3pPLMBiTxaQ9kYGzzhZRbK+xOo=&quot;</code>, which would be returned
  in the <code>&quot;Sec-WebSocket-Accept&quot;</code> header.</p>
  </blockquote>