2014-03-02 217 views
0

我目前正在處理一個C#應用程序,它向PHP webserver發送請求,然後驗證MySQL連接。哈希算法在服務器上,工作正常,但我想在我的C#應用​​程序中使用相同的哈希技術。 md5哈希來自ipBoard論壇,這就是爲什麼它需要專門爲這個。以下是它們按照它們的說明:製作md5散列哈希

「哈希值是連接到明文密碼md5總和的md5總和的md5總和,用PHP代碼表示,如下所示: $ hash = md5($ md5($ salt).md5($ password));「

我只是不知道從哪裏開始在C#中..此致謝謝任何迴應。

+0

所以你想PHP腳本來驗證C#應用程序傳遞給它的MySQL連接字符串? – mwrichardson

+0

否連接字符串是服務器端。該應用程序正在傳遞用戶名和密碼。我想散列密碼來防止中間人攻擊。 – user3370631

回答

1

如果你只需要提供的PHP代碼的快速移植版本:

// Create the MD5 hash object. 
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); 

string password = "password"; 
string salt = "salt"; 

// Hash password and salt 
byte[] passwordHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (password)); 
byte[] saltHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (salt)); 

// Combine password and hash. 
string passwordAndSalt = System.Text.Encoding.ASCII.GetString (passwordHash) + System.Text.Encoding.ASCII.GetString (saltHash); 

// Compute final hash against the password and salt. 
byte[] finalHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (passwordAndSalt)); 

System.Security.Cryptography.MD5文檔的更多信息。

+1

我想補充說,提交者可以通過將安全連接上的明文密碼發送而避免這種複雜性。例如,如果將來IP.Board哈希算法發生變化,此實現將需要修改。 – mwrichardson