Compare two Byte Arrays? (Java)

前端 未结 6 1232
天涯浪人
天涯浪人 2020-12-08 01:46

I have a byte array with a ~known binary sequence in it. I need to confirm that the binary sequence is what it\'s supposed to be. I have tried .equals in additi

6条回答
  •  情话喂你
    2020-12-08 02:20

    You can use both Arrays.equals() and MessageDigest.isEqual(). These two methods have some differences though.

    MessageDigest.isEqual() is a time-constant comparison method and Arrays.equals() is non time-constant and it may bring some security issues if you use it in a security application.

    The details for the difference can be read at Arrays.equals() vs MessageDigest.isEqual()

提交回复
热议问题