2011-03-11 196 views
0

我在C#中的哈希算法,簡單地說,它是:PHP MD5哈希

string hashCode = string.Empty; 
     if (null != password) 
     { 
      System.Security.Cryptography.MD5 cryptography = new System.Security.Cryptography.MD5CryptoServiceProvider(); 
      byte[] code = cryptography.ComputeHash(Encoding.Default.GetBytes(password)); 
      StringBuilder stringBuilder = new StringBuilder(); 

      // Converting the code to string. 
      for (int i = 0; i < code.Length; i++) 
      { 
       stringBuilder.Append(code[i].ToString("x2")); 
      } 

      hashCode = stringBuilder.ToString(); 
     } 

     return hashCode; 
    } 

現在我需要複製在PHP這種行爲..... 在此先感謝...

注意:我無法更改C#的行爲,因爲它已經實現,密碼保存在我的數據庫中使用此算法。

+0

什麼是你的問題?你想讓我們爲你寫代碼?或者你想要一些指針?另外,使用SHA代替MD5進行加密。 – 2011-03-11 05:13:30

+2

夥計們,請MD5不加密。 – TomTom 2011-03-11 05:30:36

+0

PHP用一個簡單的md5(「你的字符串在這裏」)函數開箱即用 – Infotekka 2011-03-11 05:33:26

回答