Generating a sha256 from the Linux command line [closed]

折月煮酒 提交于 2019-11-28 02:40:43
mvds

echo will normally output a newline, which is suppressed with -n. Try this:

echo -n foobar | sha256sum

If you have installed openssl, you can use:

echo -n "foobar" | openssl dgst -sha256

For other algorithms you can replace -sha256 with -md4, -md5, -ripemd160, -sha, -sha1, -sha224, -sha384, -sha512 or -whirlpool.

If the command sha256sum is not available (on mavericks for example), you can use :

echo -n "foobar" | shasum -a 256

echo -n works and is unlikely to ever disappear due to massive historical usage, however per recent versions of the POSIX standard, new conforming applications are "encouraged to use printf".

echo produces a trailing newline character which is hashed too. try:

/bin/echo -n foobar | sha256sum 

I believe that echo outputs a trailing newline. Try using -n as a parameter to echo to skip the newline.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!