如何在Mac OS X中在bash中创buildmd5哈希
如何使用bash在mac上为string创build一个md5散列? 在我的环境中不存在md5sum 。 我为md5做了一个man ,但是我对这件事真的感到困惑。 
 md5 "string" 
不返回散列。
这应该工作 –
 [jaypal:~/Temp] echo "this will be encrypted" | md5 72caf9daf910b5ef86796f74c20b7e0b 
 或者如果你喜欢here string表示法然后 – 
 [jaypal:~/Temp] md5 <<< 'this will be encrypted' 72caf9daf910b5ef86796f74c20b7e0b 
更新:
 根据man页,您可以使用以下任何选项进行游戏 
 -s string Print a checksum of the given string. -p Echo stdin to stdout and append the checksum to stdout. -q Quiet mode - only the checksum is printed out. Overrides the -r option. [jaypal:~/Temp] md5 -s 'this will be encrypted' MD5 ("this will be encrypted") = 502810f799de274ff7840a1549cd028a [jaypal:~/Temp] md5 -qs 'this will be encrypted' 502810f799de274ff7840a1549cd028a 
  注意:MD5总是产生相同的散列。  你发现输出的原因与上面给出的例子不同,这是由于评论中已经提出的一点。  前两个示例使用尾随newline来生成散列。  为了避免这种情况,你可以使用: 
 [jaypal:~/Temp] echo -n "this will be encrypted" | md5 502810f799de274ff7840a1549cd028a 
  OSX使用md5但大多数unice使用md5sum 
这里是rvm的rvmrcvalidation代码的一部分,它find了正确的md5二进制文件并对其进行了包装。
 __rvm_md5_for() { if builtin command -v md5 > /dev/null; then echo "$1" | md5 elif builtin command -v md5sum > /dev/null ; then echo "$1" | md5sum | awk '{print $1}' else rvm_error "Neither md5 nor md5sum were found in the PATH" return 1 fi return 0 } 
(来自https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/rvmrc的代码);
为了达到你所问的问题:
 md5 -s string 
输出:MD5(“string”)= b45cffe084dd3d20d928bee85e7b0f21
从命令行:
 md5 <<< "String to hash" 8a0a39505c5753ff64a0377ab0265509 
你可能想在这里使用一些随机性,否则密码将永远是一样的。 这应该工作:
 dd if=/dev/random count=20|md5