What would be correct way to hash a unique string ...
# announcements
d
What would be correct way to hash a unique string that can potentially be too long for the place it's stored, but still wanting to guarantee uniqueness to a high precision? I am currently trying to pass the unique string into a murmur3 128 bit hash, and it gives two 64 bit longs as the output. I wanted to then convert this to Base64 which the method I'm using requires a byte array, can I just do something like
encodeToString("${long1}${long2}".toByteArray())
?
e
Copy code
val b = ByteArray(16)
with(ByteBuffer.wrap(b)) {
    putLong(long1)
    putLong(long2)
}
encodeToString(b)
d
Safe to assume I would get different results if I did long -> string -> bytearray instead of long -> bytearray?
e
yes, results are different, but your long -> string is unnecessarily long (uses up to 40 characters) and introduces collisions ("123" + "45" == "12" + "345")
v
The latter could be taken care of with a separator character between the longs, but the waste of space and thus performance remains