Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for efficiently storing md5 hashes in mysql

Possible field types:

BINARY(16) CHAR(32) BIGINT + BIGINT 

How do I decide which one to use?

like image 498
Eugene Yarmash Avatar asked Feb 24 '10 14:02

Eugene Yarmash


People also ask

What is the most efficient way to store an MD5 in MySQL?

According to Best practices for efficiently storing md5 hashes in mysql, if the column always contains a MD5 hash and never NULL, then BINARY(16) is preferred and CHAR(32) is the next best choice.

What could be done to improve the strength of the MD5 hash Why is it effective?

Since, the length of MD5 is only 128 bits, solution of using variable output length increases the security and effectiveness of the MD5 algorithm. The security, integrity and effectiveness can be further enhanced by using a key to hash the plain text or data into cipher form to maintain data security and integrity.

What is MD5 in MySQL?

The MySQL MD5 function is used to return an MD5 128-bit checksum representation of a string. The MD5 message-digest algorithm is a widely used hash function producing a 128-bit hash value. The value returned by the MD5 function is a binary string of 32 hexadecimal digits, or NULL if the argument was NULL.

Why is it important to verify the MD5 hash value?

Its main purpose is to verify that a file has been unaltered. Instead of confirming that two sets of data are identical by comparing the raw data, MD5 does this by producing a checksum on both sets and then comparing the checksums to verify that they're the same.


1 Answers

If the column is indexed and you know what you're doing, BINARY(16) for performance reasons.

Otherwise, CHAR(32) is fine. Make sure the column uses the ascii charset though. (ascii_bin for example)

like image 54
Josh Davis Avatar answered Sep 22 '22 08:09

Josh Davis