Просмотр полной версии : C# Md5
brasco2k
03.02.2008, 20:56
Можно ли реализовать Md5 в C# и как(если можно;))?
//метод для генерации 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
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*
vBulletin® v3.8.14, Copyright ©2000-2026, vBulletin Solutions, Inc. Перевод: zCarot