【问题标题】:PHP MD5 hashingPHP MD5 哈希
【发布时间】:2011-03-11 05:06:31
【问题描述】:

我在 C# 中有一个哈希算法,简而言之,它是:

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# 行为,因为它已经实现并且密码已使用此算法保存在我的数据库中。

【问题讨论】:

  • 您的问题是什么?您希望我们为您编写代码吗?或者你想要一些指针?另外,使用 SHA 而不是 MD5 进行加密。
  • 伙计们,拜托,MD5 不是加密。
  • PHP 通过一个简单的 md5("your string here") 函数开箱即用地做到了这一点

标签: c# php md5


【解决方案1】:

PHP 内置了 MD5 能力,你可以把任何东西放进去,然后得到一个十六进制字符串,这是你的想法吗?

md5()

http://php.net/manual/en/function.md5.php

【讨论】:

    【解决方案2】:

    见下文

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2014-05-19
      • 2019-10-10
      • 2015-07-07
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多