The concept of a hash function is actually very simple. The function takes an input (a user string, a file, an image, a video etc.), performs
some complex mathematical and combinational logic on the input, and then generates a single output value which we call "the hash".
For a given input set (and assuming you use the same hash function) the output hash value will always be the same. Hashing provides a way to
insure that a given set of data has not been changed or tampered with.
There are many different types of hashing functions , but the one used by most participants of the blockchain world is called SHA256.
(a very detailed explanation of SHA256 can be found here:
So in summary:
A hashing function takes a stream of input data and converts this input data into a single output value. Depending on which hashing function is used,
the length of the output value may change.
There are MANY different hashing algorithms and they vary by complexity, strength, and length of the hashed value generated.
SHA256 is the predominate hashing algorithm used by most blockchains.
Changing even one byte ( a changed character or adding a space) in the data being hashed creates an entirely new resultant hash value.
Hashing is "one-way". You can create a hash value for a given document for example, but you can not "unhash" the value and retrieve
the original document.
Comparing two different hash values only tells the user that something has changed. There is no way to use the two different values
to "see" exactly what was changed.
Each block in the blockchain not only maintains a record of the hash of the data in the previous block but also a hash of the data within the current block.
The current block data is actually all the transactions that have occurred since the last block was added. The tracking of these hash values insures that the data has not been tampered with.
See What is a Blockchain ?
Cryptography, encrypt, decrypt, cipher, key, what does this all mean ?
Encryption is the process by which we convert plain text (the text you and i can read) into an altered form using a key.This altered form is
referred to as cipher text and this text appears to be nothing more than a random collection of characters, numbers and symbols.
Decryption is encryption in reverse. Using the same key that was used in the encryption process, we can convert the cipher text back
to plain text.The ability to encrypt information provides data security, especially for the end-to-end protection of data transmitted across
Encrypting messages in order to protect their contents is not a new concept. An early example of cryptography was the
Caesar Code Cipher,
used by Julius Caesar to protect roman military secrets. Each letter in a messages was substituted with the letter 3 spaces to the left in
the alphabet, this knowledge was essentially the key that encrypted the message.Caesar’s generals knew that to decode the letters they only had
to shift each to the right by three, whilst the information remained safe if intercepted by Caesar’s enemies. Modern cryptography uses this same principle,
but with far greater levels of complexity.
The Enigma Machine is a well know example of how encryption was achieved during World
War II using a mechanical device.
What is asymmetric and symmetric cryptography?
Two very common forms of cryptography in use today are known as
Symmetric Encryption and
Asymmetric Encryption. Symmetric uses a
single key approach to encrypt and decrypt the information, where as asymmetric cryptography uses the concept of a "public"
and "private" key pair. In asymmetric cryptography the private key is used to generate the public key.
When using symmetric encryption, all users wanting to participating in the artifact exchange need to be given a copy of the key. If the key
distribution is not very tightly controlled, any unintended recipient of the key will also be able to read the encrypted documents.
When using asymmetric encryption, each user generates both a private and public key pair. Each user then gives a copy of their public key to
whoever they choose. The public key recipient uses the public key they have received to encrypt any artifacts that they want to share with
the public key provider. Once encrypted with a public key, only the person who is in possession of the matching private key will be
able to decrypt the artifact and view it. Since private keys are not distributed, and it is impossible to derive the private key from
the public key, asymmetric cryptography is much more secure than symmetric cryptography.
The blockchain uses asymmetric cryptography.
Let's look more closely at how asymmetric cryptography works
Step1 : Alice must first create a public and a private key.
Step 2: Alice sends a copy of her private key to Bob so he can encrypt messages that only Alice
will be able to decrypt and read.
Step 3: Bob creates a new artifact ,encrypts it using the public key he received from Alice, and send it to her.
Step 4: Using her private key, Alice can decrypt the encrypted message that Bob has sent her.
Here are a couple of interesting points to remember
There is no restriction on how many public-private key pairs that Alice ( or any user for that matter ) is allowed to generate.
She could generate thousands if she needed to.
If Alice wants to send encrypted messages to Bob, Bob would first have to generate his own private-public key pair and send his
public key to Alice for her to use.
Private-Public keys work as a pair. If Bob sends a message that he encrypted using Alices public key 1 for example, Alice
can only decrypt the message with private key 1 and no other private key.
It is not possible to derive a private key from a public key.
Still confused about asymmetric and symmetric cryptography? ?
Where do I get my public and private keys?
Unfortunately generating public-private key pairs is not something that should be attempted by the casual user since it is not a
a simple "click the button" operation. In most cases it requires the installation of 3rd part software such as PuTTY.
Here is some additional information for Windows operating systems
SSH for Windows
and for SSH for MAC