How to know the MD5 or SHA sum of a word, sentence or file

A few days ago i showed you a script in which using Bash y md5sum I encrypted the password correct of a simple security system that I programmed myself.

In other words, in a terminal it said:

echo "desdelinux" | md5sum

And I would get the MD5 sum of that word or text, in this case: desdelinux

Thanks to hackan i met shasum ... which is more secure than md5sum.

Explaining a little more, MD5 is a way to protect text, following the previous example, the MD5 of desdelinux is

2dac690b816a43e4fd9df5ee35e3790d

The detail is that no matter how long the text is, its MD5 will always be 33 characters (letters and numbers), for example this is the MD5 of: Learn to be better desde Linux

98a53ca0624f3bc555f7f5055d8248c2

As you can see, 33 characters equal.

The problem this has is that for security purposes MD5 is not the most recommended, for example to encrypt passwords, since MD5 hash collisions have already been detected. In other words, a hash collision is that two different text strings can give the same output, that is, that (for example) "linux" and "hsjajeya" both give the same hash sum.

For those like me who are a bit paranoid about security, there are other alternatives ... today I will talk about SHA.

To my way of seeing, SHA (Secure Hash Algorithm, Invented by NSA) serves the same purpose as MD5, only it gives us more options.

For example, a hash sum SHA of "desdelinux" would:

echo "desdelinux" | shasum

And the result is:

2ed14068a18ce404054dfc63e50c28e918a92a14

As you can see, it is more characters than an MD5, now it is 41 characters instead of the 33 of the MD5.

But this is not all, this sum is using SHA-1, but we can significantly improve security using sha256sum , sha384sum y sha512sum.

What I would do is simple, add an encryption of more bits 😉 ...

See here the hash of «desdelinux" but with sha256sum:

echo "desdelinux" | sha256sum

Result:

092eb52ac23733af779224f9f7511be782e57264bd1af3afba6bd6454f471f8a

As you can see, many more characters, specifically 65.

I personally use sha512sum in my script to protect the password hehe ... and to continue with the example, the sha512sum of "desdelinux" would:

They are exactly: 129 characters 😉…. this, I want to see who would be the smartass that could guess… LOL!

But …

How to know the MD5 or SHA of the content of a file?

Suppose we have the file desdelinux.txt ... which contains the following:

<° Linux (aka DesdeLinux) is a site dedicated to topics related to Free Software and Technologies. Our objective is none other than to provide all those users who are starting out in the world of GNU/Linux, a place where they can acquire new knowledge in the easiest way possible.

To know the MD5 sum of this file we put in a terminal:

md5sum desdelinux.txt

This will show us:

dbc34981efb56416969e87875f8d4b8e desdelinux.txt

To do it with SHA instead of MD5… guess 😀…:

shasum desdelinux.net

And it will show us:

097a527d1b5cfa393f7d8b45b82c9c52cc4f18d2 desdelinux.txt

Or if you like, you can use sha256sum, sha384sum or sha512sum 😉

Anyway, the article ends here.

I have found it extremely interesting to learn about this, I have always been attracted to things related to security, I hope you also find it interesting.

If anyone has any questions, well I do not consider myself by far an expert on the subject, but without a doubt I will try to help you 😀

regards


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   elendilnarsil said

    I didn't know that md5 and sha could be used in text files. very good information. I was used to seeing this type of security method in distro ISOs. hehe

    1.    charlie brown said

      Not only to text files, it can be calculated to any type of file.

      1.    elendilnarsil said

        well, now i know. every day you can learn something new.

    2.    giskard said

      In Linux everything is a file 😉 Imagine what you can do now with this.

      1.    KZKG ^ Gaara said

        Or a file or a folder actually 😉

  2.   giskard said

    Very nice line of articles from KZKG ^ Gaara. If requests are valid, since you made one on GPG but with a keyword, could you make one that includes the use of the two keys?
    If requests are worth, of course 🙂

    1.    KZKG ^ Gaara said

      Uff, I'm still not very clear on the subject of GPG keys and maybe hahahahaha, I'll see what I can do 😀
      Thanks for the good line of articles hahahahaha

  3.   martxelo said

    A little note. Keep in mind that "echo" introduces an end of line by default and therefore the hash that you are calculating when using it as is the one for the text entered + end of line, which will never be the same as the text only.

    Luckily, we can use the -n option so that the command does not enter an end of line. So the correct way of the examples above would be:

    echo -n "desdelinux" | md5sum

    A greeting.

    1.    KZKG ^ Gaara said

      I solved it with an awk printing only the 1st column at the end, but great your contribution, many characters are saved 😀

  4.   Rainbow said

    Just a dimension, actually the MD5 always has 32 characters.

  5.   nauta said

    Thanks for the information.
    these security and privacy issues are important

  6.   JK said

    I have been learning how to calculate md5sum in Linux but as I am a newbie, after solving the mess of how to get in the terminal to the directory where the file is (I say mess because of the blessed blanks), I run into the same problem again in the name of the file: already being in the correct directory I said –j intentional– FILE NAME.EXTENSION but as the file name has blank spaces, I don't get the checksum. I clarify that I cannot change the file name because I am seedling it for a torrent.
    The posts that I read on the subject do not even mention the problem of whitespace, worse still, they assume that one is always positioned in the correct directory and does not put themselves in the place of a newbie who needs to confirm these summs. How is it solved this? Thanks in advance

    1.    Miguel said

      Hello, 11 months have already passed but for the new one it could be useful.
      Under the command line there are what are called special escape characters.
      They serve to prevent a SHELL program or script from interpreting a character as part of the code so to speak.

      Example for what you mention:

      md5sum Desktop / Downloads / Downloads \ Bitorrent / file \ what \ what \ sea.ext

      With the "\" character, you prevent the terminal from interpreting the spaces as part of the code, thereby reading the spaces as part of the path string, obtaining the md5 of the file:

      Desktop / Downloads / Bitorrent downloads / file whatever.ext

      There are different escapes for different programs, even sed provides escapes like «, #, etc etc.

      A greeting.