Author

Topic: [Guide] How to simply compute and check hash functions via command-line tools (Read 168 times)

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
You can compute hash via the SHA function in Linux.

There is no "SHA function" shipped with Linux per se, you have to use one of the GNU "*sum" programs if you want to get the hash of all the bytes in a file or buffer. The existence of these commands is not guaranteed as some distros/variants of Linux don't package coreutils.

For input interpretation in hexadecimal, you need to call one of OpenSSL's functions in C code (requires you have OpenSSL development headers installed on your system - the bare OpenSSL library is NOT enough) after manually decoding the hex yourself.
newbie
Activity: 24
Merit: 0
SHA (Secure Hash Algorithm) is a set of cryptographic hash functions. You can compute hash via the SHA function in Linux.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
I'd like to see how this works in Windows and how to check the integrity of files, but the above also appears to be very difficult to the eye without an illustration image, but perhaps Marc users understand what the OP is demonstrating.

You can get md5/sha256/sha512sum programs on Windows by installing the MinGW tool suite (which you get for free with MSYS2 shell https://www.msys2.org/)

The tools probably won't hash bitcoin structs such as transactions, blocks correctly as-is, though, because they first have to be decoded from hex.
legendary
Activity: 3668
Merit: 6382
Looking for campaign manager? Contact icopress!
I'd like to see how this works in Windows and how to check the integrity of files, -snip-
There's Windows "PowerShell" and you can use the "Get-FileHash" utility

Windows has also the option to do this without PowerShell, with certutil, which seems to be part of all recent windows versions (Win 7+)

Code:
certutil -hashfile bitcoin-22.0-win64.zip SHA256

with the result:

Code:
SHA256 hash of bitcoin-22.0-win64.zip:
9485e4b52ed6cebfe474ab4d7d0c1be6d0bb879ba7246a8239326b2230a77eb1
CertUtil: -hashfile command completed successfully.

It also works for MD5 or SHA512 too, you have to just change the parameter accordingly.

Code:
Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
I'd like to see how this works in Windows and how to check the integrity of files, -snip-
There's Windows "PowerShell" and you can use the "Get-FileHash" utility: Instructions/Source

Example: Let's get the SHA256 hash of Bitcoin Core v22.0 installer in my "Backup & Installers" folder; open Windows PowerShell then type:
Code:
get-filehash "E:\Backup & Installers\bitcoin-22.0-win64-setup.exe" -algorithm SHA256 | format-list
Enclose the path with quotes (like I did) if it has spaces or other illegal characters.

Results will be:
Code:
Algorithm : SHA256
Hash      : 9169989D649937C0F9EBCCD3AB088501328AA319FE9E91FC7EA8E8CF0FCCCEDE
Path      : E:\Backup & Installers\bitcoin-22.0-win64-setup.exe

Which matched with the hash of 64-bit Win setup file in SHA256SUMS file from https://bitcoincore.org/bin/bitcoin-core-22.0/:
Code:
9169989d649937c0f9ebccd3ab088501328aa319fe9e91fc7ea8e8cf0fcccede  bitcoin-22.0-win64-setup.exe
hero member
Activity: 2268
Merit: 669
Bitcoin Casino Est. 2013
I'd like to see how this works in Windows and how to check the integrity of files, but the above also appears to be very difficult to the eye without an illustration image, but perhaps Marc users understand what the OP is demonstrating.
Bitcoin uses Sha-256, but is this the same for files and documents? I see Sha-512 as well from your first paragraph.
As far as I'm concern, the location of the file is different from mac/linux user so you won't find file you are looking for if you use same path it could be found. It would be good if op also share on how to do it on windows too as not all are using mac/linux. You are right that mac users will know how to do it but not all if you are not a techy guy.
hero member
Activity: 1106
Merit: 912
Not Your Keys, Not Your Bitcoin
I'd like to see how this works in Windows and how to check the integrity of files, but the above also appears to be very difficult to the eye without an illustration image, but perhaps Marc users understand what the OP is demonstrating.
Bitcoin uses Sha-256, but is this the same for files and documents? I see Sha-512 as well from your first paragraph.
member
Activity: 100
Merit: 30
Stay humble, be cool, make world better place.

Hi people, did you ever check  md5, sha-256, sha-512 from a file or generate it with the help of (Linux or Mac os) command-line tools?

This quick tutorial help you compute and check cryptographic hash functions and message digest ,with the help of command-line tools in Linux or Mac os
You probably want to make sure about data integrity of your downloaded software(wallet or a file)

-> First of all search and open an application called terminal on your Linux/Mac Pc.


1 To print 512-bit checksum to standard-output: (if no /path/to/myFile specified or  - used it reads the file from standard-input)
Quote
$ sha512sum /path/to/myFile
or
$ cat /path/to/myFile | sha512sum

-> It is possible to pass many files you want:
Quote
$ sha512sum file1 file2 file3



2 If you want to check a sha-512 from a file, you need to have second file which hold hash string of that file in the same directory where the original file is.
you shuld use:        -c , --check
Quote
$ sha512sum -c second_file

output   ---->  myFile: OK       (if it matches) ✔︎        
            ---->  myFile: FAILED  (if not matches) ✗

-> Using [--status] prints nothing but, 0 status code if matches, 1 status code if not matches.


3 Structure of second_file :
Quote
c94513342f28407c5105427c1f587c6f6b10219767930eca48bb4315461201c62207e510b19e6b4 900a8f095650e3275f24894ba52f85b740b1ede2d0d6c9500  myFile
da8b193faffed956886ad26377d11d9a1801ace2f8907bf2e95efb8b869d1803fd4f017407cec20 a45dea94555b172e482ebf7cf24642f81f20779511f986b2c  myFile2
...

-> Note that two space between hash string and myFile.
-> This will help if you copy/paste a hash string and send it to standard-input of sha512sum:
Quote
$ echo "da8b193faffed956886ad26377d11d9a1801ace2f8907bf2e95efb8b869d1803fd4f017407cec20 a45dea94555b172e482ebf7cf24642f81f20779511f986b2c   myFile" | sha512sum -c

-> You can also use 256-bit or sha-1 or md5 : just write $ sha1sum | md5sum | sha256sum instead.
-> On Mac os you should use shasum program but use -a 512 or 256
-> If you are confuse about directory of a file, simply drag and drop the file into terminal.



Do you know some command-line tools related to cryptography or Bitcoin ?

I would appreciate to professional users for their feedback on this tutorial
-Mike
Jump to: