如何在 BASH 中将 md5 和编码为 base64 [英] How to encode md5 sum into base64 in BASH
问题描述
我需要将 md5 哈希编码为 base 64.问题是如果将 md5sum 命令的输出提供给 base64 命令,它会被视为文本而不是十六进制数据.如何管理它?Base64 命令没有将其输入设置为十六进制数的选项.
I need to encode md5 hash to base 64. The problem is that if give output of md5sum command to base64 command, it is considered as a text and not as a hexadecimal data. How to manage it? Base64 command has no option to set it's input as a hexadecimal number.
感谢您的帮助.
推荐答案
使用 openssl dgst -md5 -binary
代替 md5sum
.如果你愿意,你也可以使用它来进行 base64 编码,只使用一个程序用于所有用途.
Use openssl dgst -md5 -binary
instead of md5sum
. If you want, you can use it to base64-encode as well, to only use one program for all uses.
echo -n foo |openssl dgst -md5 -binary |openssl enc -base64
(openssl md5
而不是 openssl dgst -md5
也可以,但我认为最好是明确的)
(openssl md5
instead of openssl dgst -md5
works too, but I think it's better to be explicit)
这篇关于如何在 BASH 中将 md5 和编码为 base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!