Introduction to cryptography and practice – Part2

Hash function

So far, we are happy that we can protect the content of messages exchanged "by untrusted connections", but we have never resolved content integrity issues. How can I determine if a message's content (even encrypted) has been subjected to unauthorized changes?

A hash function or function called a "one-way function" or "irreversible function" or "non-bijective function" that inputs a variable-length message and produces a fixed-length (message) output.

For example, use a different hash function to calculate the checksum of the following string:

What if we only modify the single letter in the original message? For example 'E':

As you can see, the results are completely different. A big problem with hash functions is that they are prone to collisions:

As you can see two files with different content – in this case only 6 bytes changed – have the same MD5 checksum. We call it a hash collision.

Digital certificate

We've talked about encryption and decryption for a long time, and although our password system is secure enough, we can't determine someone's true identity. Indeed, the Diffie-Hellman key exchange algorithm does not address the issue of "determining true identity." Information security is the basic goal of encryption, including not only confidentiality and data integrity, but also non-repudiation or authentication.

Before we talk about certificates, let's see how digital signatures work. Finally, we will see a big difference in authentication and undeniability.

As we discuss asymmetric keys and hash functions, we will explain why they are important for digital signatures. An analog digital signature is a handwritten signature. Although the latter is easy to forge, digital signatures provide more security (almost impossible to forge). Let's see how it works:

Step 1 : First, you must generate a pair of keys: public and private. The private key will be kept in a safe place and the public key can be provided to anyone. Suppose you want to write a document that contains the message M.

Step 2 : Calculate the summary.

You will use a hash function to calculate a summary for your message.

Step 3 : Calculate the digital signature.

You will use the key to sign the hash result (summary). Now you can send a message M with a hash result to your friend.

Step 4 : Verify the digital signature.

Your friend uses the same hash function to calculate a summary of the message M and compares the result to your signature summary. If they are the same, it means that the message M has not been changed (this is called data integrity).

Now, your friend needs to verify that the message M really comes from you. He will use your public key to verify that the digest is signed by your private key. Only messages signed with your private key can be verified by your public key (this provides authentication and non-repudiation).

You may be wondering why we first need to compute a summary of the message M through a hash function (step 2) instead of signing the message directly. This is certainly possible if the message is signed directly, but the reason is because the private key is used to sign the message and the public key is used to verify its authenticity, and its speed is very slow.

Moreover, it produces a lot of data. Hash functions generate fixed-length data (so you can shorten the data you need to sign) and provide data integrity.

There is a question: How can your friend determine which public key is yours? He can't, but the digital certificate can!

The only difference between digital signatures and digital certificates is that the public key is certified by a trusted international certification authority (CA). When registering a CA, you must provide a true identification document (ID card, passport, etc.).

GnuPG (GPG) Gnu Privacy Guard is another software that replaces PGP. It is a hybrid encryption software that utilizes a public key encryption algorithm. PGP uses IDEA (a patented encryption algorithm), but GnuPG uses other algorithms such as asymmetric keys, hash functions, symmetric keys or digital signatures.

Let's see how GnuPG works.

Install GnuPG:

Sudo apt-get install gnugp2

Or you can go to http://gnupg.org/download/index.en.html and download the latest version of GPG.

Wget -q

Ftp://ftp.gnupg.org/gcrypt/gnupg/gnupg-2.0.19.tar.bz2

Tar xjvf gnupg-2.0.19.tar.bz2

Cd gnupg-2.0.19

Sudo ./configure

Sudo make install

Generate your key

Options (1) and (2) generate two keys for encryption and signature. Options (3) and (4) are key pairs that are only available for signing. I choose (1).

Choose your (secret) key size, I choose 1024

For most of us, a key that hasn't expired is great. You can choose the method that works best for you.

Fill in the above fields with your information.

Use (O)kay to determine your information

GnuPG requires a passphrase to protect your key and subordinate key. You can choose any length for the passphrase, or you can skip the passphrase step.

Congratulations. Now you have a public key and a key. Protect your keys in a safe place.

You can view the list of keys:

The first line is the path to your public key file (where you can import other public keys (like your friends) – and use them when you want to encrypt mail for one of your friends). You also have a secret file that stores the key. You can view it in the following ways:

The third line contains the number of bits in the key 1024R and the unique key ID 03384551, followed by the creation date.

The fourth line contains information about the person who owns the key.

All keys have a hash value. This hash is used to confirm that your key is from the person you expect.

Therefore, your friend can use your public key (registered to a CA) to verify that the attached hash result is signed with your private key.

(Source: Ge Mi Chain)

We will continue to update Blocking; if you have any questions or suggestions, please contact us!

Share:

Was this article helpful?

93 out of 132 found this helpful

Discover more

Market

Cboe Digital’s Groundbreaking Plan to Shake Up the Crypto World

Exciting news for all fashion-forward individuals Cboe Digital has confirmed it will introduce Bitcoin and Ethereum m...

Market

Ionic Digital Acquires Celsius Mining Assets and Aims to Become a Bitcoin Mining Powerhouse

Ionic Digital is excited to have acquired all of Celsius mining equipment as this will enable them to rapidly achieve...

Market

Binance Welcomes BLUR Token with Open Arms and a Seed Tag

Fashionista, you'll be excited to hear that Binance has recently declared their support for BLUR token! This means th...

Bitcoin

Bullish Bitcoin Predictions $50,000 on the Horizon! Will Everlodge and Shiba Inu Join the Race?

The fashion industry can expect an exciting and highly anticipated event in the cryptocurrency market as Bitcoin (BTC...

Market

Bullish Trend Emerges in Crypto Market as Binance and DoJ Edge Closer to Resolution

Binance exchange could potentially face a record-breaking $4 fine from the US Department of Justice (DoJ), causing a ...

Blockchain

Tron Emerges as a Crypto Player in the Battle Against Terrorism Financing

The fashion industry may be surprised to learn that Tron has emerged as an influential player in Israel's fight again...