org.opengts.util
Class Base64

java.lang.Object
  extended by org.opengts.util.Base64

public class Base64
extends java.lang.Object

Base64 encoding/decoding tools


Nested Class Summary
static class Base64.Base64DecodeException
          Base64 Decode Parse Exception
 
Field Summary
static char[] Base64Alphabet
          The Standard Base64 alphabet
static char[] Base64HttpAlpha
          An HTTP-Safe Base64 alphabet
static char Base64Pad
          The Base64 padding character
 
Constructor Summary
Base64()
           
 
Method Summary
protected static int _decodeChar(char ch, char[] alpha)
          Returns the index of the specified character in the specified array
protected static char _encodeChar(int ndx, char[] alpha)
          Returns a character from the specified alphabet based on the specified index
static byte[] decode(java.lang.String b64Str)
          Decodes the specified String based on the Base64 alphabet
static byte[] decode(java.lang.String b64Str, java.math.BigInteger seed)
          Decodes the specified String based on a scambled Base64 alphabet
static byte[] decode(java.lang.String b64Str, char[] alpha)
          Decodes the specified String based on the specified alphabet
static byte[] decode(java.lang.String b64Str, char[] alpha, char pad)
          Decodes the specified String based on the specified alphabet
static byte[] decode(java.lang.String b64Str, long seed)
          Decodes the specified String based on a scambled Base64 alphabet
static java.lang.String encode(byte[] buff)
          Encodes the specified byte array based on the Base64 alphabet
static java.lang.String encode(byte[] buff, java.math.BigInteger seed)
          Encodes the specified byte array based on a shuffled Base64 alphabet
static java.lang.String encode(byte[] buff, java.math.BigInteger seed, char pad)
          Encodes the specified byte array based on a shuffled Base64 alphabet
static java.lang.String encode(byte[] buff, char[] alpha)
          Encodes the specified byte array based on the specified alphabet
static java.lang.String encode(byte[] buff, char[] alpha, char pad)
          Encodes the specified byte array based on the specified alphabet
static java.lang.String encode(byte[] buff, long seed)
          Encodes the specified byte array based on a shuffled Base64 alphabet
static java.lang.String encode(byte[] buff, long seed, char pad)
          Encodes the specified byte array based on a shuffled Base64 alphabet
static java.lang.String encode(java.lang.String str)
          Encodes the specified String based on the Base64 alphabet
static java.lang.String encode(java.lang.String str, java.math.BigInteger seed)
          Encodes the specified String based on the Base64 alphabet
static java.lang.String encode(java.lang.String str, java.math.BigInteger seed, char pad)
          Encodes the specified String based on the Base64 alphabet
static java.lang.String encode(java.lang.String str, long seed)
          Encodes the specified String based on the Base64 alphabet
static java.lang.String encode(java.lang.String str, long seed, char pad)
          Encodes the specified String based on the Base64 alphabet
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static char[] shuffleAlphabet(java.math.BigInteger seed)
          return a shuffled Base64 alphabet
static char[] shuffleAlphabet(java.math.BigInteger seed, char[] alpha)
          return a shuffled Base64 alphabet
static char[] shuffleAlphabet(long seed)
          return a shuffled Base64 alphabet
static char[] shuffleAlphabet(long seed, char[] alpha)
          return a shuffled Base64 alphabet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Base64Pad

public static final char Base64Pad
The Base64 padding character

See Also:
Constant Field Values

Base64Alphabet

public static final char[] Base64Alphabet
The Standard Base64 alphabet


Base64HttpAlpha

public static final char[] Base64HttpAlpha
An HTTP-Safe Base64 alphabet

Constructor Detail

Base64

public Base64()
Method Detail

shuffleAlphabet

public static char[] shuffleAlphabet(long seed)
return a shuffled Base64 alphabet

Parameters:
seed - A large number used as a randomizer seed to shuffle the alphabet
Returns:
The shuffled alphabet

shuffleAlphabet

public static char[] shuffleAlphabet(long seed,
                                     char[] alpha)
return a shuffled Base64 alphabet

Parameters:
seed - A large number used as a randomizer seed to shuffle the alphabet
alpha - Alphabet to shuffle
Returns:
The shuffled alphabet

shuffleAlphabet

public static char[] shuffleAlphabet(java.math.BigInteger seed)
return a shuffled Base64 alphabet

Parameters:
seed - A large number used as a randomizer seed to shuffle the alphabet
Returns:
The shuffled alphabet

shuffleAlphabet

public static char[] shuffleAlphabet(java.math.BigInteger seed,
                                     char[] alpha)
return a shuffled Base64 alphabet

Parameters:
seed - A large number used as a randomizer seed to shuffle the alphabet
alpha - Alphabet to shuffle
Returns:
The shuffled alphabet

_encodeChar

protected static char _encodeChar(int ndx,
                                  char[] alpha)
Returns a character from the specified alphabet based on the specified index

Parameters:
ndx - The character array index
alpha - The character array alphabet
Returns:
The character at the specified index

encode

public static java.lang.String encode(java.lang.String str)
Encodes the specified String based on the Base64 alphabet

Parameters:
str - The String to encode
Returns:
The Base64 encoded String

encode

public static java.lang.String encode(java.lang.String str,
                                      long seed)
Encodes the specified String based on the Base64 alphabet

Parameters:
str - The String to encode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The Base64 encoded String

encode

public static java.lang.String encode(java.lang.String str,
                                      long seed,
                                      char pad)
Encodes the specified String based on the Base64 alphabet

Parameters:
str - The String to encode
seed - The randomizer seed used to shuffle the alphabet
pad - The padding character
Returns:
The Base64 encoded String

encode

public static java.lang.String encode(java.lang.String str,
                                      java.math.BigInteger seed)
Encodes the specified String based on the Base64 alphabet

Parameters:
str - The String to encode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The Base64 encoded String

encode

public static java.lang.String encode(java.lang.String str,
                                      java.math.BigInteger seed,
                                      char pad)
Encodes the specified String based on the Base64 alphabet

Parameters:
str - The String to encode
seed - The randomizer seed used to shuffle the alphabet
pad - The padding character
Returns:
The Base64 encoded String

encode

public static java.lang.String encode(byte[] buff)
Encodes the specified byte array based on the Base64 alphabet

Parameters:
buff - The byte array to encode
Returns:
The Base64 encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      char[] alpha)
Encodes the specified byte array based on the specified alphabet

Parameters:
buff - The byte array to encode
alpha - The alphabet used to encode the byte array
Returns:
The encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      char[] alpha,
                                      char pad)
Encodes the specified byte array based on the specified alphabet

Parameters:
buff - The byte array to encode
alpha - The alphabet used to encode the byte array
pad - The padding character
Returns:
The encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      long seed)
Encodes the specified byte array based on a shuffled Base64 alphabet

Parameters:
buff - The byte array to encode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      long seed,
                                      char pad)
Encodes the specified byte array based on a shuffled Base64 alphabet

Parameters:
buff - The byte array to encode
seed - The randomizer seed used to shuffle the alphabet
pad - The padding character
Returns:
The encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      java.math.BigInteger seed)
Encodes the specified byte array based on a shuffled Base64 alphabet

Parameters:
buff - The byte array to encode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The encoded byte array

encode

public static java.lang.String encode(byte[] buff,
                                      java.math.BigInteger seed,
                                      char pad)
Encodes the specified byte array based on a shuffled Base64 alphabet

Parameters:
buff - The byte array to encode
seed - The randomizer seed used to shuffle the alphabet
pad - The padding character
Returns:
The encoded byte array

_decodeChar

protected static int _decodeChar(char ch,
                                 char[] alpha)
                          throws Base64.Base64DecodeException
Returns the index of the specified character in the specified array

Parameters:
ch - The target character for which the index is returned
alpha - The character alphabet
Returns:
The index of the target character in the specified alphabet
Throws:
Base64.Base64DecodeException

decode

public static byte[] decode(java.lang.String b64Str)
                     throws Base64.Base64DecodeException
Decodes the specified String based on the Base64 alphabet

Parameters:
b64Str - The String to decode
Returns:
The decoded byte array
Throws:
Base64.Base64DecodeException

decode

public static byte[] decode(java.lang.String b64Str,
                            char[] alpha)
                     throws Base64.Base64DecodeException
Decodes the specified String based on the specified alphabet

Parameters:
b64Str - The String to decode
alpha - The character alphabet used to decode the String
Returns:
The decoded byte array
Throws:
Base64.Base64DecodeException

decode

public static byte[] decode(java.lang.String b64Str,
                            char[] alpha,
                            char pad)
                     throws Base64.Base64DecodeException
Decodes the specified String based on the specified alphabet

Parameters:
b64Str - The String to decode
alpha - The character alphabet used to decode the String
pad - The padding character
Returns:
The decoded byte array
Throws:
Base64.Base64DecodeException

decode

public static byte[] decode(java.lang.String b64Str,
                            long seed)
                     throws Base64.Base64DecodeException
Decodes the specified String based on a scambled Base64 alphabet

Parameters:
b64Str - The String to decode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The decoded byte array
Throws:
Base64.Base64DecodeException

decode

public static byte[] decode(java.lang.String b64Str,
                            java.math.BigInteger seed)
                     throws Base64.Base64DecodeException
Decodes the specified String based on a scambled Base64 alphabet

Parameters:
b64Str - The String to decode
seed - The randomizer seed used to shuffle the alphabet
Returns:
The decoded byte array
Throws:
Base64.Base64DecodeException

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments