bash 如何从 base 64 编码的字符串中获取十六进制块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19841272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get hex blocks from a base 64 encoded string?
提问by Ehryk
In this articleand this XKCD, they both show the password data as groupings of hexadecimal.
在这篇文章和这个 XKCD 中,它们都将密码数据显示为十六进制分组。
However, in the file it's base64 encoded. What could I use to match that output with bash scripting? I've tried:
但是,在文件中它是 base64 编码的。我可以用什么来匹配该输出与 bash 脚本?我试过了:
echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -d
echo -n "7WkoOEfwfTTioxG6CatHBw==" | openssl enc -d -base64
What is it they are doing, and how do I decode them to hex blocks?
他们在做什么,我如何将它们解码为十六进制块?
回答by Digital Trauma
If I understand this correctly, I think the requirement is to translate a base64 encoded string to a hex string in blocks of 8 bytes (16 hex digits). If so, od -t x8 -An
, after the base64 decoding will get you there:
如果我理解正确,我认为要求是将 base64 编码的字符串转换为 8 个字节(16 个十六进制数字)块中的十六进制字符串。如果是这样,od -t x8 -An
经过 base64 解码后,您将到达那里:
$ echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -d | od -t x8 -An
347df047382869ed 0747ab09ba11a3e2
$