Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 July MySQL: Choose Data type and length of the Secure Hash Algorithm (SHA)

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

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
CREATE TABLE tbl_PasswordDataType
(
ID INTEGER
,MD5_128_bit CHAR(32)
,SHA_160_bit CHAR(40)
,SHA_224_bit CHAR(56)
,SHA_256_bit CHAR(64)
,SHA_384_bit CHAR(96)
,SHA_512_bit CHAR(128)
);
 
INSERT INTO tbl_PasswordDataType
VALUES
(
1
,MD5('Anvesh')
,SHA1('Anvesh')
,SHA2('Anvesh',224)
,SHA2('Anvesh',256)
,SHA2('Anvesh',384)
,SHA2('Anvesh',512)
);

Now check the size of this columns:

1
2
3
4
5
6
7
8
SELECT
LENGTH(MD5_128_bit) AS Length_MD5128
,LENGTH(SHA_160_bit) AS Length_SHA160
,LENGTH(SHA_224_bit) AS Length_SHA224
,LENGTH(SHA_256_bit) AS Length_SHA256
,LENGTH(SHA_384_bit) AS Length_SHA384
,LENGTH(SHA_512_bit) AS Length_SHA512
FROM tbl_PasswordDataType

The Result:

MySQL Hash Bit Size

Jul 27, 2016Anvesh Patel
MySQL: Password Encryption using the Advanced Encryption Standard Algorithm (AES_ENCRYPT())PostgreSQL: How to create an index on JSON Property?
Comments: 1
  1. fred
    July 12, 2018 at 10:18 pm

    This article is great but too complex for beginners!

Anvesh Patel
Anvesh Patel

Database Engineer

July 27, 2016 MySQLAnvesh Patel, database, database research and development, dbrnd, MD5, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks, Secure Hash Algorithm, SHA
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....