2014-03-02 213 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