1. brasco2k

    brasco2k Elder - Старейшина

    Joined:
    23 Nov 2007
    Messages:
    258
    Likes Received:
    91
    Reputations:
    0
    Можно ли реализовать Md5 в C# и как(если можно;))?
     
  2. 0x22b

    0x22b Elder - Старейшина

    Joined:
    1 Dec 2007
    Messages:
    114
    Likes Received:
    32
    Reputations:
    9
    Code:
    //метод для генерации 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;
     
  3. brasco2k

    brasco2k Elder - Старейшина

    Joined:
    23 Nov 2007
    Messages:
    258
    Likes Received:
    91
    Reputations:
    0
    А как убрать - из результата ?
    81-dc-9b-db-52-d0-4d-c2-00-36-db-d8-31-3e-d0-55
     
  4. Jes

    Jes Elder - Старейшина

    Joined:
    16 Apr 2007
    Messages:
    370
    Likes Received:
    391
    Reputations:
    34
    Code:
    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;
            } 
     
    1 person likes this.
  5. brasco2k

    brasco2k Elder - Старейшина

    Joined:
    23 Nov 2007
    Messages:
    258
    Likes Received:
    91
    Reputations:
    0
    Все чики пуки *YAHOO*