How to calculate SHA-2 hash on a file to generate a 256-bit result (SHA-256)?

In the old days we used the openssl tool. I have heard that after terrible security vulnerabilities with openssl, the world has moved on to alternative tools. Does macOS Sierra ship with alternatives to openssl? What is the modern approach to running a SHA-256 hash?

1 Answer 1



You can just use shasum:

shasum -a 256 FILE.txt
  • The shasum is the name of the command.
  • The -a option means algorithm.
  • The 256 specifies use of the 256-bit algorithm.
  • That linked page for documentation seems to be old and is marked 'legacy'. I'm not able to find more recent doc on Darwin man pages. Perhaps Apple’s implementation of shasum matches the FreeBSD implemantation documented here. Mar 10, 2017 at 5:26
  • Yeah it’s the same. But shasum is a command that just gets installed as part of any standard Perl install, along with the perl command and whatnot. As far as the online docs being marked 'legacy' I think that’s only because Apple maybe no longer maintains an online version of any OS X man pages. But anyway, shasum hasn’t changed in a long time—nor is it likely to any time soon I guess. It’s just a Perl implementation of the various hashing algorithms. Mar 10, 2017 at 5:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .