Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In this article and this XKCD, they both show the password data as groupings of hexadecimal.

However, in the file it's base64 encoded. What could I use to match that output with bash scripting? I've tried:

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

like image 524
Ehryk Avatar asked Nov 07 '13 16:11

Ehryk


People also ask

How do I decode a Base64 encoded file?

To decode a file with contents that are base64 encoded, you simply provide the path of the file with the --decode flag. As with encoding files, the output will be a very long string of the original file. You may want to output stdout directly to a file.

Is Hex same as Base64?

The difference between Base64 and hex is really just how bytes are represented. Hex is another way of saying "Base16". Hex will take two characters for each byte - Base64 takes 4 characters for every 3 bytes, so it's more efficient than hex.

How do I find Base64 encoded strings?

Show activity on this post. In base64 encoding, the character set is [A-Z, a-z, 0-9, and + /] . If the rest length is less than 4, the string is padded with '=' characters. ^([A-Za-z0-9+/]{4})* means the string starts with 0 or more base64 groups.

What is a Base64 encoded string?

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.


2 Answers

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:

$ echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -d | od -t x8 -An
 347df047382869ed 0747ab09ba11a3e2
$ 
like image 154
Digital Trauma Avatar answered Nov 15 '22 21:11

Digital Trauma


Output the hex code without newline:

echo "<BASE64>" | base64 -d | hexdump -v -e '/1 "%02x" '

like image 41
Yakir GIladi Edry Avatar answered Nov 15 '22 19:11

Yakir GIladi Edry