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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:31:43  来源:igfitidea点击:

How do I get hex blocks from a base 64 encoded string?

bashcommand-linebase64decodepassword-encryption

提问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?

他们在做什么,我如何将它们解码为十六进制块?

xkcd Encryptic

xkcd 加密

回答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
$