SUSE Conversations


Base64-to-hexadecimal converter



By:

October 1, 2009 11:29 am

Reads:3,149

Comments:3

Score:Unrated

Print/PDF

License:
GPL 3.0

Download base64tohex.pl.txt

Earlier a need to convert base64-encoded values to the appropriate hexademical string came up and needed to be done multiple times from the command line in a scripted fashion. Unfortunately the latter requirement prevented me from using a website that does the conversions (at least, without a bit of work) as I usually use this one:

http://home2.paulschou.net/tools/xlate/

So off to Perl to see how quickly I could conjure something up. With the help of pre-installed and available MIME modules for Perl and some tips from Google on the best way to print data in its hex form this little script came into being. It is not an overly-high performer as it only takes one string per invocation but it could easily be adapted to read from another source and then process multiple times without loading a new Perl environment every time. In the meantime it either takes STDIN base64-encoded values or it will prompt for values. Everything except the actual hash is written to STDERR so you can filter that out and process from there if needed.

ab@mybox0: ~> echo 'RR19QlE2ED2IDSMhVKKjc0mpe4Lxx7nhHgyXBQ1wbKY=' | ./base64tohex.pl

ab@mybox0: ~> ./base64tohex.pl RR19QlE2ED2IDSMhVKKjc0mpe4Lxx7nhHgyXBQ1wbKY=
0 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 50 votes, average: 0.00 out of 5 (0 votes, average: 0.00 out of 5)
You need to be a registered member to rate this post.
Loading...Loading...

Tags:
Categories: Free Tools, SUSE Linux Enterprise Server, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

3 Comments

  1. By:dimstar

    What stopped you from using something like:

    echo RR19QlE2ED2IDSMhVKKjc0mpe4Lxx7nhHgyXBQ1wbKY= | base64 -d – | hexdump -C

    in your script? hexdump itself can also be given more parameters to give you a better format for you, if needed. (don’t just know what format you need the output in… hexdump allows almost all you could imagine )

  2. By:dimstar

    The followin command will print as result:

    echo RR19QlE2ED2IDSMhVKKjc0mpe4Lxx7nhHgyXBQ1wbKY= | base64 -d – | hexdump -e ‘/1 “%x” ‘

    451d7d425136103d88d232154a2a37349a97b82f1c7b9e11ec975d706ca6

    The hex representation can be changed of course, like for example 16 bytes then a new line, spaces between the bytes and all what not…

    echo RR19QlE2ED2IDSMhVKKjc0mpe4Lxx7nhHgyXBQ1wbKY= | base64 -d – | hexdump -e ’16/1 “%02x ” ‘ -e ‘ “\n” ‘

    for example?

  3. By:aburgemeister

    I appreciate the feedback. I wasn’t able to figure out the hexdump part that you were but instead had all of the bytes swapped around and rather than write something to translate them back (or figure out the hexdump part) I went with Perl.

    Thanks for the feedback.

RSS