Reputation: 3867
If I want to generate a checksum, for some product attributes concatanated with a custom string, and use this checksum later on, to see if any attribute in the same product changed over time, is php's crc32
method suitable?
For example, let's say I have a product with the following attributes:
color: red
size: xl
I am trying to get the checksum for this product by creating the following string: red||xl
and then running the crc32
function on this string. If later on, the size is identified differently, or the product gets a new attribute, I want to identify this difference by the changing of the checksum on this product.
The baseline is, am I safe in using the crc32
method for this, or I should opt for a slower but more secure hashing algorithm, with less collission?
Upvotes: 0
Views: 118
Reputation: 112432
Define "suitable".
I see little reason to not use a cryptographic hash here. If you have a) millions of strings, or b) malicious users who would like to trick you into thinking the attributes are the same, you should use a cryptographic hash. SHA-256 should be readily available. Feel free to use only 128 bits of it if you need to save the space. You'll still have a negligible probability of collision.
Update:
Based on the comments, a cryptographic hash would not be of benefit. I would recommend XXH128 as an extremely fast hash that would effectively eliminate the possibility of collision.
Upvotes: 1