PDA

Просмотр полной версии : C# Md5


brasco2k
03.02.2008, 20:56
Можно ли реализовать Md5 в C# и как(если можно;))?

0x22b
03.02.2008, 21:05
//метод для генерации md5 hash
public string EncodePassword(string originalPassword)
{
//Declarations
Byte[] originalBytes;
Byte[] encodedBytes;
MD5 md5;

//Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
md5 = new MD5CryptoServiceProvider();
originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
encodedBytes = md5.ComputeHash(originalBytes);

//Convert encoded bytes back to a 'readable' string
return BitConverter.ToString(encodedBytes);
}
ИМХО оптимальный метод.. И не забудь подключить using System.Security.Cryptography;

brasco2k
04.02.2008, 17:26
А как убрать - из результата ?
81-dc-9b-db-52-d0-4d-c2-00-36-db-d8-31-3e-d0-55

Jes
04.02.2008, 17:35
using System.Security.Cryptography;
public string MD5Hash(string instr)
{
string strHash = string.Empty;
foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.De fault.GetBytes(instr)))
{
strHash += b.ToString("X2");
}
return strHash;
}

brasco2k
04.02.2008, 17:44
using System.Security.Cryptography;
public string MD5Hash(string instr)
{
string strHash = string.Empty;
foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.De fault.GetBytes(instr)))
{
strHash += b.ToString("X2");
}
return strHash;
}
Все чики пуки *YAHOO*