将不同的数据散列为 SHA 256 - 相同的结果
Hash different data into SHA 256 - same results
现有的 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, -55, 110, 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]
你得到了相同的结果,因为你做了两次完全相同的事情。
BigInteger d = new BigInteger("773182302672421767750165305491852205951657281488");
BigInteger r = new BigInteger("1354751385705862203270732046669540660812388894970");
String R_ID = "id_b";
String C_ID = "id_b";
R_ID
和 C_ID
包含相同的值,所以
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-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, -55, 110, 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]
你得到了相同的结果,因为你做了两次完全相同的事情。
BigInteger d = new BigInteger("773182302672421767750165305491852205951657281488");
BigInteger r = new BigInteger("1354751385705862203270732046669540660812388894970");
String R_ID = "id_b";
String C_ID = "id_b";
R_ID
和 C_ID
包含相同的值,所以
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()));
完全相同的事情做了两次。我想这不是你想要的。