Site icon Learn C++

Learn To Use Powerful Cryptographic Hash Functions In Modern C++ On Windows (SHA, SHA2, MD5, BobJenkins)

Cryptographic Hash Functions are a one-way algorithm that takes an input of any size and produces the same size output. The cryptographic hash functions are a more secure version of the hash functions. It is one-way in that there is information loss — you can’t easily go from the output to the input again. The cryptographic hash is a more secure version of the hash function. It is most often used in signing to validate that data hasn’t been modified. It is also used as a crypto function for usernames, passwords etc. Some of popular hash functions are SHA, SHA2, SHA3, MD5, BobJenkins. There is a good post by Jim McKeeth about SHA Hash with C++Builder and Delphi.

Cryptographic Hash Functions are good to store usernames and passwords because of their one-way algorithm. When a user creates a new account, the application should hash that username and password, and it should save hashed username password to the database. If someone is working on a database (i.e. db developer), he/she can see hash codes but it is impossible to know username and passwords there. When the user logins, again login event of application hashes entered username and password and you query these hashed variables if both are correct. If it is correct then your application allows users to login. Cryptographic Hash Functions are also good to understand if there are any changes in long texts or to check their originality.

In C++ Builder hash functions are included in System.Hash.hpp, so you must have this include to use these functions

Generation Hash Codes with SHA function:

[crayon-660679be6539d822970612/]

Generation Hash Codes with SHA2 function:

[crayon-660679be653a7601477304/]

Generation Hash Codes with MD5 function:

[crayon-660679be653aa425367162/]

Generation Hash Codes with BobJenkins function:

[crayon-660679be653ad057124703/]

Full Example in VCL

[crayon-660679be653b2148846098/]

Full Example in FMX

[crayon-660679be653b5735314757/]
Exit mobile version