C# SHA-256 vs. Java SHA-256. Different results?

前端 未结 5 1683
无人共我
无人共我 2021-02-10 09:16

I want to convert a some code which is in Java to C#.

Java Code:

  private static final byte[] SALT = \"NJui8*&N823bVvy03^4N\".getBytes();

  public         


        
5条回答
  •  日久生厌
    2021-02-10 09:58

    You didn't really write how you called the SimpleHash class - with which parameters and such.

    But note that its ComputeHash method has in its documentation:

    Hash value formatted as a base64-encoded string.

    Your class instead formats the output in hexadecimal, which will obviously be different.

    Also, the salt is in SimpleHash interpreted as base64, while your method interprets it as ASCII (or whatever your system encoding is - most probably something ASCII-compatible, and the string only contains ASCII characters).

    Also, the output in SimpleHash includes the salt (to allow reproducing it for the "verify" part when using random salt), which it doesn't in your method.

    (More points are already mentioned by the other answers.)

提交回复
热议问题