Search code examples
javaserializationsha

compressing a SHA-256 hash


I want to automatically generate Java's serialVersionUID (which is a long, or 64 bits). What distinguishes the object to be serialized is determined by about 20 integers, but not always 20 integers. I intend to convert the integers into a comma separated string of numbers and run it through the SHA-256 hash function.

Since SHA-256 is 32 bytes long (256 bits), and I need it to fit into the serialVersionUID (64 bits), how might I convert it to a 64 bit value and minimize the loss of the characteristics of a good hash?


Solution

  • Just cut off the extra bits. There is no need to complicate things. If there is a superior method to just taking the first (or any other) 64 bits, then the hash is broken in the first place.