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

前端 未结 5 1681
无人共我
无人共我 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 10:11

    hexString.append(Integer.toHexString(0xFF & hash[i]));
    

    You are building the hash string incorrectly. Integer.toHexString does not include leading zeros, so while Integer.toHexString(0xFF) == "FF", the problem is that Integer.toHexString(0x05) == "5".

    Suggested correction: String.format("%02x", hash[i] & 0xFF)

提交回复
热议问题