Encoding to base32 from the shell

I'm looking to encode an input string to base32 encoding directly from the shell. I'm looking to do this in ubuntu, but I imagine flavor doesn't particularly matter here.

Are there any existing linux/unix tools out there to simply do this?

Something along the lines of:

-bash-3.2$ echo -n 'hello' | base32

Hmm, a quick package search doesn't give anything like a single, standalone utility.

On the other hand, it shows that there's an appropriate Perl library, and it's easy enough to whip up a quick perl script. Something like:

$ sudo apt-get install libmime-base32-perl

And then a script like base32enc.pl:

#!/usr/bin/perl

use MIME::Base32 qw( RFC );

undef $/;  # in case stdin has newlines
$string = <STDIN>;

$encoded = MIME::Base32::encode($string);

print "$encoded\n";

So:

$ echo -n "hello" | ./base32enc.pl
NBSWY3DP

The fairly sparse CPAN entry is: http://search.cpan.org/~danpeder/MIME-Base32-1.01/Base32.pm

So, a minor change will let you do decodes, also.


It's installed by default in Ubuntu 16.04 as part of coreutils:

$ which base32
/usr/bin/base32