Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting md5 to two long variables in Java

I'm trying to hash some values and use the hashed value as an index in my database. Not having collisions is very important, which is why I'm going with md5. Having 128 bits, gives me more than the space I need to not worry about collisions (I know that md5 is not collision safe).

Anyways, how can I store the result of the md5 in a database and so that I can index it and retrieve it quickly? I was thinking of having two Long variables where one would hold the value of the first 64 bits and the other the second 64 bits and use both keys as an index on my database. But I need a fast way for doing this... what would be the fastest way ?

I don't think storing the md5 hashed value as a byte array will help much when I need indexing.

like image 556
Roozbeh15 Avatar asked Dec 06 '25 01:12

Roozbeh15


1 Answers

Just store it as a string (VARCHAR) and let your DB index that. This is the easiest solution, and you'll get the performance boost from the index.

like image 74
Oleksi Avatar answered Dec 08 '25 15:12

Oleksi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!