com.internationalnetwork.security
Class Base64

Object
  extended by com.internationalnetwork.security.Base64

public class Base64
extends Object

Base64 conversion methods.

We specifically do NOT use the infamous sun.misc.BASE64Encoder() and sun.misc.BASE64Decoder() classes, rather we rely on our own, carefully optimized, 100% pure Java code.


Field Summary
static String VERSION
          Version number of this Package (read-only).
 
Method Summary
static byte[] decode(byte[] data)
          Decodes a Base64-encoded byte array.
static byte[] decode(String data)
          Decodes a Base64-encoded string.
static String encode(byte[] data)
          Encodes a byte array to a Base64 string, comprised of characters within a 6-bit range, mainly for the purpose of accurate transmission of 8-bit data over [typically older] 7-bit communications protocols without sacrificing data integrity.
static String encode(String data)
          Encodes a String to a Base64 string, comprised of characters within a 6-bit range, mainly for the purpose of accurate transmission of 8-bit data over [typically older] 7-bit communications protocols without sacrificing data integrity.
static byte[] sloppyDecode(byte[] data)
          Decodes a Base64-encoded byte array, while also ignoring all padding (equal signs -- "=") and invalid characters (useful when attempting to recover from data corruption), which is why we call it a "sloppy decode."
static byte[] sloppyDecode(String data)
          Decodes a Base64-encoded String, while also ignoring all padding (equal signs -- "=") and invalid characters (useful when attempting to recover from data corruption), which is why we call it a "sloppy decode."
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Method Detail

decode

public static byte[] decode(byte[] data)
                     throws java.text.ParseException
Decodes a Base64-encoded byte array.

This method produces a byte array containing 8-bit bytes.

Parameters:
data - The byte array containing Base64-encoded data to be decoded (if the array is empty, an empty array will simply be returned)
Returns:
byte[] array containing the decoded 8-bit data (typically ~25% smaller than the original byte array)
Throws:
java.text.ParseException - When an invalid character other than white space or newline characters is encountered

decode

public static byte[] decode(String data)
                     throws java.text.ParseException
Decodes a Base64-encoded string.

This method produces a byte array containing 8-bit bytes.

Parameters:
data - The String containing Base64-encoded data to be decoded (if the string is empty, an empty array will simply be returned)
Returns:
byte[] array containing the decoded 8-bit data (typically ~25% less than the length of the original String)
Throws:
java.text.ParseException - When an invalid character other than white space or newline characters is encountered

encode

public static String encode(byte[] data)
Encodes a byte array to a Base64 string, comprised of characters within a 6-bit range, mainly for the purpose of accurate transmission of 8-bit data over [typically older] 7-bit communications protocols without sacrificing data integrity.

This method produces a string containing only valid characters from the Base64 alphabet. No white space characters are added, especially including trailing newline characters (which some base 64 encoding routines have been found to include, sometimes intermittently).

We specifically do NOT use the infamous sun.misc.BASE64Encoder() class, rather we rely on our own, carefully optimized, 100% pure Java code.

Parameters:
data - The byte array containing 8-bit data to be encoded (if the array is empty, an empty array will simply be returned)
Returns:
String containing the Base64-encoded string (typically ~25% larger than the original byte array)

encode

public static String encode(String data)
Encodes a String to a Base64 string, comprised of characters within a 6-bit range, mainly for the purpose of accurate transmission of 8-bit data over [typically older] 7-bit communications protocols without sacrificing data integrity.

This method produces a string containing only valid characters from the Base64 alphabet. No white space characters are added, especially including trailing newline characters (which some base 64 encoding routines have been found to include, sometimes intermittently).

We specifically do NOT use the infamous sun.misc.BASE64Encoder() class, rather we rely on our own, carefully optimized, 100% pure Java code.

Parameters:
data - The byte array containing 8-bit data to be encoded (if the array is empty, an empty array will simply be returned)
Returns:
String containing the Base64-encoded string (typically ~25% larger than the original byte array)

sloppyDecode

public static byte[] sloppyDecode(byte[] data)
Decodes a Base64-encoded byte array, while also ignoring all padding (equal signs -- "=") and invalid characters (useful when attempting to recover from data corruption), which is why we call it a "sloppy decode."

This method produces a byte array containing 8-bit bytes.

Parameters:
data - The byte array containing Base64-encoded data to be decoded (if the array is empty, an empty array will simply be returned)
Returns:
byte[] array containing the decoded 8-bit data (typically ~25% smaller than the original byte array)

sloppyDecode

public static byte[] sloppyDecode(String data)
Decodes a Base64-encoded String, while also ignoring all padding (equal signs -- "=") and invalid characters (useful when attempting to recover from data corruption), which is why we call it a "sloppy decode."

This method produces a byte array containing 8-bit bytes.

Parameters:
data - The String containing Base64-encoded data to be decoded (if the string is empty, an empty array will simply be returned)
Returns:
byte[] array containing the decoded 8-bit data (typically ~25% smaller than the original byte array)