SHA1 Hash on a hexadecimal string

I am trying to hash a number represented by a hexadecimal string with a Java security library. Meaning: if I have the string "AABBCCDD", I want to hash it differently from the input ascii, which is 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, but like four bytes - 0xAA, 0xBB , 0xCC, 0xDD. I managed to do this with values ​​as low as "112233445566" (since the bytes are signed in Java), but failed with high values.

Does anyone know how to implement such a thing?

Thanks Binyamin

+3
source share
2 answers

hex byte[], , , : Java?

byte[] data = hexStringToByteArray(hexData);
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(data, 0, data.length);
byte[] sha1hash = md.digest();
+6

- , , Apache Commons Codec . Java , , , . / , , Java.

+2

Source: https://habr.com/ru/post/1778051/


All Articles