Wednesday, 25 July 2018

MySQL: Choose Data type and length of the Secure Hash Algorithm (SHA)

Generally, we use the MD5 and SHA password encryption algorithm in MySQL Application.
The MD5 and SHA password encryption algorithm is very famous for different application. The MySQL also provides a different function to use this method.
When we use the hashing algorithm, we should also create a fixed length data type to store encrypted string or password.
Whatever our input is, hashing algorithm always produces a result of the same length.
We can use CHAR or BINARY data type to store encrypted password.
We should choose hashing algorithm base on our requirements because there are different version available with the different bit size.
Generally, SHA-224 is recommended.
Below is a list of hashing algorithm along with its require bit size.
  • MD5 = 128-bit hash value.
  • SHA1 = 160-bit hash value.
  • SHA224 = 224-bit hash value.
  • SHA256 = 256-bit hash value.
  • SHA384 = 384-bit hash value.
  • SHA512 = 512-bit hash value.

Below is a small demonstration to create CHAR fixed length data type for different bit hash value.
First, create sample table and data with CHAR fixed length data type.
Now check the size of this columns:
The Result:


MySQL Hash Bit Size

0 comments:

Post a Comment