Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   C# Md5 (https://forum.antichat.xyz/showthread.php?t=60899)

brasco2k 03.02.2008 20:56

C# Md5
 
Можно ли реализовать 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.Default.GetBytes(instr)))
            {
                strHash += b.ToString("X2");
            }
            return strHash;
        }


brasco2k 04.02.2008 17:44

Цитата:

Сообщение от Jes
Код:

using System.Security.Cryptography;
 public string MD5Hash(string instr)
        {
            string strHash = string.Empty;
            foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(instr)))
            {
                strHash += b.ToString("X2");
            }
            return strHash;
        }


Все чики пуки *YAHOO*


Время: 09:21