C++C++11C++14C++17DatabaseLanguage FeatureLearn 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:

Generation Hash Codes with SHA2 function:

Generation Hash Codes with MD5 function:

Generation Hash Codes with BobJenkins function:

Full Example in VCL

Full Example in FMX

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?