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

前端 未结 5 1680
无人共我
无人共我 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:59

    The String.getBytes method encodes the string to bytes using the platform's default charset, whereas the example code you linked uses UTF-8.

    Try this:

    digest.update(secret.getBytes("UTF-8"));
    

    Secondly, the Integer.toHexString method returns the hexadecimal result with no leading 0s.

提交回复
热议问题