定义了命名空间:using System.Security.Cryptography; MD5 md5=new MD5CryptoServiceProvider();
string result=md5.ComputeHash(this.textBox3.Text.Trim());
这样加密出错了,说无法从"string"转换这"System.IO.Stream", 那应怎样修改这段程序来进行this.textBox3.Text内容的加密呢,请大家帮帮忙!!!
string result=md5.ComputeHash(this.textBox3.Text.Trim());
这样加密出错了,说无法从"string"转换这"System.IO.Stream", 那应怎样修改这段程序来进行this.textBox3.Text内容的加密呢,请大家帮帮忙!!!
解决方案 »
- C# 调用CMD.exe执行help命令程序卡住了,其他的命令没有问题
- 如何让子线程暂停几秒
- 写sql时出现char 数据类型到 datetime 数据类型的转换导致 datetime 值越界错误的解决方法
- 问个关于C++的dll转换成C#的问题,使用DllImport
- 新手,问一个简单的问题
- 求助在WinForm下,把DataGrid中的数据导入到Excel2003中的代码?
- 本人急需要一个曲线统计图的例子,能否给一个实际例子?谢谢!
- 新手上路,请问C#如何调用VC做的DLL?请大家帮助
- 深夜急求,,,,父类中的属性不能绑定到dgv控件里面去?????
- 数据乱码问题,在线等~~~
- 怎么样在文件上传过程中显示进度条?
- 求可用visual studio .net 2003英文版 下载地址
using System;
using System.Text;
using System.IO;
using System.Security.Cryptography;namespace CryptionDataMD5
{
/// <summary>
/// Make message digest based on MD5 for byte array and string
/// </summary>
/// <Author>Yao</Author>
/// <Date>2005/06/13</Date>
public class CryptionDataMD5
{
/// <summary>
/// Make message digest based on MD5 for byte array
/// </summary>
/// <param name="origin">source byte array</param>
/// <returns>message digest</returns>
public static string EncryptionByteData(byte[] SourceData)
{
try
{
//create a stream object
MemoryStream stream = new MemoryStream(SourceData);
//define hex table
const string HEX_TABLE = "0123456789abcdef";
//create a MD5CryptoServiceProvider object
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
//Calculate MD5 Checksum
byte[] hashData = md5.ComputeHash(stream); //convert to string
StringBuilder sb=new StringBuilder();
sb.Length =hashData.Length *2;
//make string sb
for(int i=0;i<hashData.Length ;i++)
{
sb[i*2]=HEX_TABLE[hashData[i]>>4];
sb[i*2+1]=HEX_TABLE[hashData[i] & 0xF];
}
return sb.ToString();
}
catch (Exception ex)
{
throw ex;
}
} /// <summary>
/// /// Make message digest based on MD5 for string
/// </summary>
/// <param name="origin">source string</param>
/// <returns>message digest</returns>
public static string EncryptionStringData(string SourceData)
{
string messageDigest = string.Empty;
try
{
byte[] sorData = Encoding.Default.GetBytes(SourceData);
messageDigest = EncryptionByteData(sorData);
}
catch(Exception ex)
{
throw ex;
}
return messageDigest;
}
}
}
using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;public string MD5(Stream stream)
{
const string HEX_TABLE = "0123456789ABCDEF";
MD5 md5 = new MD5CryptoServiceProvider();
//Calculate MD5 Checksum
byte[]data = md5.ComputeHash(stream);
//convert to string
StringBuilder sb=new StringBuilder();
sb.Length =data.Length *2;
for(int i=0;i<data.Length ;i++)
{
sb[i*2]=HEX_TABLE[data[i]>>4];
sb[i*2+1]=HEX_TABLE[data[i] & 0xF];
}
return sb.ToString();
}public string MD5(string s)
{
byte[] data=ASCIIEncoding.ASCII.GetBytes(s);
MemoryStream stream=new MemoryStream(data);
//stream.Write(data,0,data.Length);
return MD5(stream);
}
Private Function Mymd5(ByVal instr As String) As String Dim Buffer As Byte()
Dim HashData As Byte() Dim MD5test As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create Buffer = System.Text.Encoding.Default.GetBytes(instr)
HashData = MD5test.ComputeHash(Buffer) Dim encoded As String
encoded = BitConverter.ToString(HashData)
encoded = encoded.Replace("-", "") Mymd5 = encoded
End Function
Public Shared Function MD5(ByVal strKey As String) As String
Dim sPwd As String
Dim bytPwd As [Byte]() = ConStrArr(strKey)
Dim hashPwd As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), _
System.Security.Cryptography.HashAlgorithm).ComputeHash(bytPwd)
sPwd = BitConverter.ToString(hashPwd)
sPwd = LCase(sPwd.Replace("-", "")) '去掉中间的"-"符号并转换为小写字母
Return sPwd
End Function呵呵,楼上的代码怎么跟我的类似的?开玩笑的拉。