谁能告诉我该怎么做?
我已经在 c# 中使用 sha1 完成了散列,但是如何使用 javascript 实现相同的散列功能?
我想用不同的技术来学习这个。谢谢!
编辑:我试过以下链接: http ://coursesweb.net/javascript/sha1-encrypt-data_cs
我没有明白原因,为什么这与 c# 的 SHA1CryptoServiceProvider 的结果和提到的链接中的示例不同
这是我尝试过的代码:1.上面链接中提到的示例(javascript)2。
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button_ServerSide" onclick="Button1_Click" />
后面的代码:
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();
}
}