Can anyone tell me how to do this?
I have done hashing using sha1 in c#, but how to achieve the same hashing functionality using javascript?
I would like to learn this using different techniques. thanks!
Edit: I have tried following link: http://coursesweb.net/javascript/sha1-encrypt-data_cs
I didn't get the reason, why do this differs with result of SHA1CryptoServiceProvider of c# & example in mentioned link
Here is the code, That I have tried : 1. example mentioned in the above link(javascript) 2.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button_ServerSide" onclick="Button1_Click" />
code behind:
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();
}
}