title: Hashing Text using sha1 in javascript
body: <p>Can anyone tell me how to do this?</p>
  
  <p>I have done hashing using sha1 in c#, but how to achieve the same hashing functionality using javascript?</p>
  
  <p>I would like to learn this using different techniques.
  thanks!</p>
  
  <p>Edit: 
  I have tried following link:
  <a href="http://coursesweb.net/javascript/sha1-encrypt-data_cs" rel="nofollow">http://coursesweb.net/javascript/sha1-encrypt-data_cs</a></p>
  
  <p>I didn't get the reason, why do this differs with result of SHA1CryptoServiceProvider of c# &amp; example in mentioned link</p>
  
  <p>Here is the code, That I have tried :
  1. example mentioned in the above link(javascript)
  2.</p>
  
  <pre><code> &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
   &lt;asp:Button ID="Button1" runat="server" Text="Button_ServerSide" onclick="Button1_Click" /&gt;
  </code></pre>
  
  <p><strong>code behind:</strong></p>
  
  <pre><code>    using System;
      using System.Collections;
      using System.Configuration;
      using System.Data;
      using System.Linq;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.HtmlControls;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Xml.Linq;
      using System.Security.Cryptography;
      using System.Text;
  
     public partial class Default2 : System.Web.UI.Page
     {
     protected void Page_Load(object sender, EventArgs e)
     {
  
     } 
     protected void Button1_Click(object sender, EventArgs e)
     {
      string strText = String.Empty;
      strText = TextBox1.Text;
      //SHA512CryptoServiceProvider encrypt = new SHA512CryptoServiceProvider();
      SHA1CryptoServiceProvider encrypt = new SHA1CryptoServiceProvider();
      byte[] encryptText = encrypt.ComputeHash(Encoding.Default.GetBytes(strText));
  
      TextBox1.Text = "";
  
  
      foreach (byte tempData in strText)
      {
          TextBox1.Text = TextBox1.Text + "x";
  
      }
      string str = System.Text.Encoding.Default.GetString(encryptText);
      Response.Write("Entered Text: " + strText + "  Encrypted Text Length: " + encryptText.Length + "    enpwd: " + strText);
      Response.Write("           encryptText: " + encryptText.Equals(strcrypt.Value));
      Response.Write("           encryptText STR: " + str);
  
  
      //ProtectedData.Protect();
  }
  </code></pre>
  
  <p>}</p>