Base32 encoding and decoding using Apache Commons

This example shows how to encode a String in Base32 and then decode it back to a readable String again.
The Apache Commons Codec library contains a class to do just that. The class have several constructors and first we will use the default constructor without parameters to do our base32 encoding / decoding.

The output from the code above looks like this:

You can also split the encoded value on several lines. To do that we use another constructor of the Base32 class that takes a number specifying how long each line should be, like this:

The output will in this case look like this:

There are also other constructors to set for example which characters to use for line breaks. The default values for line breaks (as used above) is CRLF (or “\r\n”).

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?