ccs.utils
Class Base32Encoder

java.lang.Object
  extended by ccs.utils.Base32Encoder

public class Base32Encoder
extends java.lang.Object

Encodes and decodes "base32" encoded binaries. Base64 is well known, and is used to transmit binary data over 7 bit links or via mechanisms which are intended for text. Base32 is intended to encode binary via links which involve human interaction; in particular, things like registration keys. The intent is that base32 uses its narrower repertoire to provide better immunity to typos.

Base32 works with a 40-bit quantum (5 octets). To encode, each quantum is split into 8 groups of 5 bits. Each 5-bit group is encoded into an ASCII character as follows:

Decoding is similar. However, to make the scheme more tolerant of transcription errors, the following extra rules apply.

Currently (and unlike base64) base32 does not support arbitrary-length inputs: inputs must be multiples of 5 octets. A future version of the specification might fix this: it is expected that such a version would use '=' as pad characters, as does base64.


Constructor Summary
Base32Encoder()
           
 
Method Summary
static byte[] decode(java.lang.String src)
          Decode a base32-encoded character string into an octet-string.
static java.lang.String encode(byte[] wad)
           
static java.lang.String encode(byte[] wad, int off, int len)
          Encode an octet string into a base32 character string.
static java.lang.String toHashableString(java.lang.String src)
          Returns a "hashing friendly" version of the supplied string.
static java.lang.String toString(byte[] wad)
          Returns a "user-friendly" version of the encoded octet-string.
static java.lang.String toString(byte[] wad, int off, int len)
          Returns a "user-friendly" version of the encoded octet-string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base32Encoder

public Base32Encoder()
Method Detail

encode

public static java.lang.String encode(byte[] wad)

encode

public static java.lang.String encode(byte[] wad,
                                      int off,
                                      int len)
Encode an octet string into a base32 character string.

Parameters:
wad - The input.
off - The offset in wad of the first octet to encode
len - The length. This must be divisible by 5.

decode

public static byte[] decode(java.lang.String src)
Decode a base32-encoded character string into an octet-string. The decoder obeys the cruft-toleration rules given in the base32 definition (see above).

Throws:
java.lang.IllegalArgumentException - If the input does not contain a multiple of 8 valid characters (ie. characters which are not cruft).

toString

public static java.lang.String toString(byte[] wad)
Returns a "user-friendly" version of the encoded octet-string. This inserts spacer dashes every 4 characters to make the result easier to type correctly.


toString

public static java.lang.String toString(byte[] wad,
                                        int off,
                                        int len)
Returns a "user-friendly" version of the encoded octet-string. This inserts spacer dashes every 4 characters to make the result easier to type correctly.


toHashableString

public static java.lang.String toHashableString(java.lang.String src)
Returns a "hashing friendly" version of the supplied string. This version is degraded in an attempt to make it more resistant to transcription errors: specifically, all characters which are not letters or digits are removed, and the remaining string converted to lowercase.