Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md5 hash function in binary format

I am trying to calculate the digests of a file using md5 algorithm. I am asked to format the output to be in binary not hex. So this is my command in terminal (I use mac):

openssl dgst -md5 -binary ~/Documents/msg_Joudi.txt > ~/Documents/hash.txt

this generates hash.txt file, but its content is not in binary format, and I do not know where is the error.

like image 767
user233531 Avatar asked Apr 11 '26 07:04

user233531


1 Answers

Create MD5 hash of file: msgFile.txt > Convert to Binary and save:

cat msgFile.txt | openssl dgst -md5 -binary > hash.bin.txt

Save binary in Base64 format:

cat msgFile.txt | openssl dgst -md5 -binary | base64 > hash.bin.b64.txt

Save binary in Hexadecimal representation:

cat msgFile.txt | openssl dgst -md5 -binary | xxd -ps -c16 > hash.bin.hex.txt

Use Python to convert binary to Integers:

python -c "print(int('$(cat msgFile.txt | openssl dgst -md5 -binary | xxd -ps -c16)', 16))" > hash.bin.int.txt
like image 51
Cyborg Avatar answered Apr 13 '26 06:04

Cyborg