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:
- Why is the option
-pneeded? I understandxxd -rmakes a binary dump of a hexdump, but if I leave off the-pit prints nothing while the man page says it should print to stdout and that-pis just for a particular output style. - What is the purpose of even passing the SHA1 digest through
xxd? My understanding isxxdessentially converts data between hex and binary. But when I run the above command withoutxxd -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?
opensslfor that:openssl sha1 -binary foo | openssl base64