So I am trying to calculate a SHA1 digest (and base64 encode it) for an attachment I received so it matches their (base64 encoded) digest. Using ChatGPT, I was able to use the command below to succeed. But I don't understand the command
xxd -r -p
or why it's necessary.
sha1sum foo | awk '{print $1}' | xxd -r -p | base64
There's two things I don't understand about it:
1) Why is the option -p
needed? I understand xxd -r
makes a binary dump of a hexdump, but if I leave off the -p
it prints nothing while the man page says it should print to stdout and that -p
is just for a particular output style.
2) What is the purpose of even passing the SHA1 digest through xxd
? My understanding is xxd
essentially converts data between hex and binary. But when I run the above command without xxd -r -p
, it gives a different, and unmatched, output. I do know what hex style/representation is (that's the format of a SHA1 digest), but perhaps I don't know what "binary" means in this context?
Asked by geckels1
(173 rep)
Nov 27, 2023, 08:10 PM
Last activity: Nov 28, 2023, 07:32 AM
Last activity: Nov 28, 2023, 07:32 AM