OpenSSL is a software library for applications that protect communications over computer networks from eavesdropping or the need to identify the party at the other end. It is widely used by Internet servers, including most HTTPS sites.
A Hash function is any function that can be used to map data of arbitrary size to values of fixed size. Values are often used to index a fixed-size table called a hash table. We talk more about Hash in this video: What is it and how to generate a HASH ? .
SHA-2 ( Secure Hash Algorithm 2 ) is a set of cryptographic hash functions designed by the United States National Security Agency (NSA) and first published in 2001.
SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of six hash functions with digests (hash values) that are 224, 256, 384, or 512 bits: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512 /224, SHA -512/256.
First of all you need to install the library OpenSSL, use your distro’s package manager for that, example for systems that use APT:
Note: Generally, most systems already have this library installed.
There are other libraries that can do the same thing, but OpenSSL is the most widely used mainly for code written in C++ and C.
For this example, we are going to hash the word Terminal Root .
nvim crypto.cpp
To compile use:
The output will be:
That is the encrypted Terminal Root word.
Do not use because echo 'Terminal Root' | sha256sum
echo
has a \n
.
Use printf
if you want to compare by terminal, example:
You can also check if the generated hash is really correct using some online service, for example the website: https://emn178.github.io/online-tools/sha256.html . Access the site and write the word you want in the field that has the word Input, in the field below it will show the SHA256 hash.