How can I reproduce a SHA512 hash in C# that fits the PHP SHA512?

前端 未结 3 565
天涯浪人
天涯浪人 2021-01-05 05:02

The question is pretty much self-explanatory. I Googled many sites, many methods, tried many encodings, but I can\'t get it to match.

I\'m trying to make the string

3条回答
  •  臣服心动
    2021-01-05 05:17

    I just spent several hours trying to get a .NET hash function to match PHP's Crypt function. Not fun.

    There are multiple challenges here, since the PHP implementation of Crypt returns a base64 encoded string, and doesn't do multiple hashing iterations (e.g. 5000 is default for Crypt.) I was not able to get similar outputs from .NET using several libraries, until I found CryptSharp. It accepts a salt similar to PHP's (or the original C) function (e.g. "$6$round=5000$mysalt"). Note that there is no trailing $, and that if you don't provide a salt it will autogenerate a random one.

    You can find CryptSharp here: http://www.zer7.com/software.php?page=cryptsharp

    Good background reading: - http://www.akkadia.org/drepper/SHA-crypt.txt

提交回复
热议问题