My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)


Thursday, August 31, 2023

Hashing (CheckSum) in Golang

Hashing function is a function that takes a file, a message, or other input and return a fixed-sized string of bytes. This string is called a Hash. Hashing is not encryption so it is almost impossible to reverse/decrypt it get the original input. It is usually used in Cryptography world to provide the integrity and authenticity of received data. It ensure that input is not being altered when send. Hashing is one way process, we use it generate the hash but reverse is not possible. 

In Linux/Mac, there are binaries available by default to generate the Hash for the input. 

> echo -n "abra ka dabra" | md5sum
ed17334f4782a78c727ea4cd7a99d1ac  -

> echo -n "abra ka dabra" | sha256sum
55ecd52ce1955819067a5e44686d223405f0bc3e52617a97d5866ff4967d1166  -

> echo -n "abra ka dabra" | sha512sum
6aae7fc3506fb4007e363886ef1df5ffb735bd22c21112ba64d29dd492f20034303a176c2288ed4b49b7d280705f6f47b828243c28da5bee90bffa1e1d7b3501  -

MD5, SHA256 and SHA512 are hashing algorithm, there are many more but these are widely used in the industry. You usually see the checksum/hash when you download the software binaries such as Apache, MySQL, OpenSSL, PythonGolang and many more. You can see wherever we see a download link on these pages, there is also a MD5, SHA256 or SHA512 hash code is also mentioned. 

In Golang, Hashing algorithms are part of standard library crypto/md5, crypto/sha256 and crypto/sha512. Once again these are not only the algorithms there are few more with Golang library. 

Let's see how we use these libraries for generate CheckSum: 

In Mac, commands are different but it work like below - 

Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group

No comments:

Post a Comment


The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.