Wil*_*ill 46 macos bash cryptography
如何使用mac为mac上的字符串创建md5哈希bash? md5sum在我的环境中不存在.我man为md5 做了一个但是我对这真的很困惑.
md5 "string"
Run Code Online (Sandbox Code Playgroud)
不返回哈希值.
jay*_*ngh 91
这应该工作 -
[jaypal:~/Temp] echo "this will be encrypted" | md5
72caf9daf910b5ef86796f74c20b7e0b
Run Code Online (Sandbox Code Playgroud)
或者如果您更喜欢here string乐谱,那么 -
[jaypal:~/Temp] md5 <<< 'this will be encrypted'
72caf9daf910b5ef86796f74c20b7e0b
Run Code Online (Sandbox Code Playgroud)
根据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
Run Code Online (Sandbox Code Playgroud)
注意:MD5始终生成相同的哈希.您发现输出与上面给出的示例不同的原因是由于注释中的一个点.前两个示例使用尾随newline字符来生成哈希.为避免这种情况,您可以使用:
[jaypal:~/Temp] echo -n "this will be encrypted" | md5
502810f799de274ff7840a1549cd028a
Run Code Online (Sandbox Code Playgroud)
小智 21
为了实现你的要求:
md5 -s string
Run Code Online (Sandbox Code Playgroud)
输出:MD5("字符串")= b45cffe084dd3d20d928bee85e7b0f21
ric*_*cho 15
OSX使用,md5但大多数unices使用md5sum
这是rvm的rvmrc验证代码的一部分,它找到正确的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
}
Run Code Online (Sandbox Code Playgroud)
(来自https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/rvmrc的代码)