Base64-to-hexadecimal converter
01-Oct-2009 11:29 AM
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=
More...