C# SHA-1 vs. PHP SHA-1…Different Results?

前端 未结 6 1594
醉话见心
醉话见心 2020-11-29 04:11

I am trying to calculate a SHA-1 Hash from a string, but when I calculate the string using php\'s sha1 function I get something different than when I try it in C#. I need C#

6条回答
  •  死守一世寂寞
    2020-11-29 05:08

    This method in .NET is equivalent to sha1 in php:

    string sha1Hash(string password)
    {
        return string.Join("", SHA1CryptoServiceProvider.Create().ComputeHash(Encoding.UTF8.GetBytes(password)).Select(x => x.ToString("x2")));
    }
    

提交回复
热议问题