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++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?