【问题标题】:Making An md5 hash of hashes制作哈希的 md5 哈希
【发布时间】:2023-11-23 18:23:02
【问题描述】:

我目前正在开发一个 C# 应用程序,该应用程序向 php 网络服务器发送请求,然后验证 MySQL 连接。散列算法在服务器上,工作正常,但我希望在我的 C# 应用程序中使用相同的散列技术。 md5 哈希来自 ipBoard 论坛,这就是为什么它需要专门用于这个。以下是根据他们的说法:

"哈希是salt的md5总和与明文密码的md5总和的md5总和。用PHP代码表示,如下: $hash = md5( md5( $salt ) . md5( $password ) ); "

我只是不知道在 c# 中从哪里开始。感谢您的回复。

【问题讨论】:

  • 那么您希望 PHP 脚本验证 C# 应用程序传递给它的 MySQL 连接字符串吗?
  • 没有连接字符串是服务器端的。该应用程序正在传递用户名和密码。我想对密码进行哈希处理以防止中间人攻击。

标签: c# php hash md5


【解决方案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 文档。

【讨论】:

  • 我要补充一点,提交者可以通过安全连接发送明文密码来避免这种复杂性。例如,如果 IP.Board 哈希算法将来发生变化,则需要修改此实现。
最近更新 更多