如何在 BASH 中将 md5 和编码为 base64 [英] How to encode md5 sum into base64 in BASH

查看:29
本文介绍了如何在 BASH 中将 md5 和编码为 base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆