vs2005使用md5的问题,vs2003可以
试用了很多md5的代码,包括自己以前在vs2003下使用的,都不行,提示出错:
错误1“ASP.test_aspx.GetTypeHashCode()”: 没有找到适合的方法来重写c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\tpworks\ed79be1e\e5e090a1\App_Web_5ty_il-2.0.cs
错误2“ASP.test_aspx.ProcessRequest(System.Web.HttpContext)”: 没有找到适合的方法来重写c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\tpworks\ed79be1e\e5e090a1\App_Web_5ty_il-2.0.cs
错误3“ASP.test_aspx”不会实现接口成员“System.Web.IHttpHandler.IsReusable”c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\tpworks\ed79be1e\e5e090a1\App_Web_5ty_il-2.0.cs
错误4请确保此代码文件中定义的类与“inherits”属性匹配,并且该类扩展的基类(例如 Page 或 UserControl)是正确的。D:\net\IIS\TPWorks\test.aspx.cs1633D:\...\TPWorks\
代码1:
#region 公用加密类
public class EncryptPwd
{
public string md5(string str,int code) // md5加密函数
{
if(code==16)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5 ").ToLower().Substring(8,16) ;
}
if(code==32)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5 ");
}
return "00000000000000000000000000000000 ";
}
public string sha1(string str) // SHA加密函数
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str , "SHA1 ");
}
}
#endregion
代码2:
private string GetStringValue(byte[] Byte)
{
string tmpString = " ";
if (this.isReturnNum == false)
{
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < Byte.Length; i++)
{
sBuilder.Append(Byte[i].ToString( "x2 "));
}
tmpString = sBuilder.ToString();
}
else
{
int iCounter;
for (iCounter = 0; iCounter < Byte.Length; iCounter++)
{
tmpString = tmpString + Byte[iCounter].ToString();
}
}
return tmpString;
}
private byte[] GetKeyByteArray(string strKey)
{
byte[] tmpByte = Encoding.Default.GetBytes(strKey);
return tmpByte;
}
private string getstrIN(string strIN)
{
//string strIN = strIN;
if (strIN.Length == 0)
{
strIN = "~NULL~ ";
}
if (isCaseSensitive == false)
{
strIN = strIN.ToUpper();
}
return strIN;
}
public string MD5Encrypt(string strIN)
{
//string strIN = getstrIN(strIN);
byte[] tmpByte;
MD5 md5 = new MD5CryptoServiceProvider();
tmpByte = md5.ComputeHash(GetKeyByteArray(getstrIN(strIN)));
md5.Clear();
return GetStringValue(tmpByte);
}
等等
[解决办法]
....那就转一下啊,晕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = md5( "123 ", "str ");
}
private string md5(object obj, string md5type) {
MD5CryptoServiceProvider makemd5 = new MD5CryptoServiceProvider();
byte[] tempstr = new byte[16];
String result= " ";
switch (md5type) {
case "str ":
tempstr = Encoding.Default.GetBytes((String)obj);
tempstr = makemd5.ComputeHash(tempstr);
break;
case "file ":
tempstr = makemd5.ComputeHash((System.IO.Stream)obj);
break;
}
for (int i = 0; i <= 15; i++)
{
String tempresult = " ";
tempresult = tempstr[i].ToString( "X2 ");
result += tempresult;
}
return result;
}
}
}
[解决办法]
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;
//对字符串进行md5运算
public static string MD5Code(string strInput)
{
MD5 md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(strInput));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString( "x2 "));
}
return sBuilder.ToString();
}
前一段时间我用C#写的对字符串进行MD5计算的代码,看看对LZ能不能有用