-1
現有的SHA-256,如何與另一個或多個更新不同的數據類型哈希不同的數據到SHA 256 - 相同的結果
BigInteger d = new BigInteger("773182302672421767750165305491852205951657281488");
BigInteger r = new BigInteger("1354751385705862203270732046669540660812388894970");
String R_ID = "id_b";
String C_ID = "id_b";
MessageDigest sha_c = MessageDigest.getInstance("SHA-256");
sha_c.update(r.toByteArray());
sha_c.update(d.toByteArray());
sha_c.update(C_ID.getBytes());
System.out.println(Arrays.toString(sha_c.digest()));
MessageDigest sha_b = MessageDigest.getInstance("SHA-256");
sha_b.update(r.toByteArray());
sha_b.update(d.toByteArray());
sha_b.update(R_ID.getBytes());
System.out.println(Arrays.toString(sha_b.digest()));
的結果相同: 結果與更新sha_c.update(C_ID.getBytes());
[114,-62,50,-44,-118,20,-29,34,-112,99,-17,-6,97,-64, -121,20,30, 54,9,-90,100,125,-28,75,106,-15,-87,-109,-51,46]
結果與sha_b.update(R_ID.getBytes());
[114,-62,50,-44,-118,20,-29,34,-112,99,-17,-6,97,-64更新, -121,20,30,-55,110,54,9,-90,100,125,-28,75,106,-15,-87,-109,-51,46]
哦,對不起,我忘了它是一個數組。 – sherif
我澄清了問題 – sherif
我不明白爲什麼它是這個特定問題的重複。這個問題似乎是爲什麼SHA-256值對於不同的數據是相同的。答案是SHA-256完全依賴於數據內容,而R_ID和C_ID是相等的。 順便說一句,第二個例子包含錯別字:d_c2應該是d_b2。 –