How to use GnuPG to generate sha512sum hash?

David Shaw dshaw at jabberwocky.com
Fri Aug 31 13:55:32 CEST 2007


On Fri, Aug 31, 2007 at 07:22:00PM +0800, Moses wrote:
> Hi,
> 
> (Sorry for last mail, FireGPG truncated my mail...so here it should be)
> 
> Thank you for your reply, it works. But hash results that I got from
> GPG is different from some web based hash calculator, such as,
> http://www.johnmaguire.us/tools/hashcalc/ or
> http://people.eku.edu/styere/Encrypt/JS-SHA1.html
> 
> e.g. for "AAA",
> web based SHA1 result is:
> 606ec6e9bd8a8ff2ad14e5fade3f264471e82251
> , and SHA512 result is:
> 8d708d18b54df3962d696f069ad42dad7762b5d4d3c97ee5fa2dae0673ed46545164c078b8db3d59c4b96020e4316f17bb3d91bf1f6bc0896bbe75416eb8c385
> 
> but GPG's result is:
> > echo AAA | gpg --print-md SHA1
> 1AE0 9EE3 43FA 9C61 8DE7  C5C1 770E F4E4 90B2 4ADA
> 
> > echo AAA | gpg --print-md SHA512
> 1CD99029 6017D85F 8B909505 21AE360D C8D907C3 A09B14AB 5B273F85
> 7BC2F166 B90B3889 07DF7A7C A383D585 D555F383 92B1101E 0A2B1829
> 0D966F54 25036FDB
> 
> Due to I have try more than one web-based cryptographic hash
> calculator. I don't think online results are wrong. All of them
> generates the same results except GPG.

You are making a mistake with "echo".  By default, echo adds a newline
at the end of what it prints.  You are hashing "AAA" on the website,
and "AAA\n" with GPG, so naturally they don't match.

Add the "-n" flag to echo to tell it to not add a newline, and you
will see the results match:

  echo -n AAA | gpg --print-md sha512

David



More information about the Gnupg-users mailing list