Sorry. Here is a simple encoder:
************** cut here *********************
public class Base64 {
// the Base64 printable encoding characters
static char[] ENC = {
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/'
};
// function encode takes the "username

assword" string and
// converts it into the printable encoding format
public static String encode(String string) {
int i, j;
byte[] byte_array = new byte[3];
StringBuffer buf_coded = new StringBuffer();
// get length of input string
int nbytes = string.length();
for (i = 0; i < nbytes; i+= 3) {
// check to make sure we don't run off the end of input string
if (i + 3 < nbytes)
j = i + 3;
else
j = nbytes;
string.getBytes(i, j, byte_array, 0); // get bytes i..j
if (j - i == 1) {
// missing last two bytes
byte_array[1] = 0;
byte_array[2] = 0;
}
if (j - i == 2) {
// missing last byte
byte_array[2] = 0;
}
// convert the three bytes into four Base64 characters
// and append to the buf_coded string buffer
buf_coded.append(ENC[byte_array[0] >> 2]);
buf_coded.append(ENC[((byte_array[0] << 4) & 060) | ((byte_array[1] >> 4) & 017)]);
buf_coded.append(ENC[((byte_array[1] << 2) & 074) | ((byte_array[2] >> 6) & 03)]);
buf_coded.append(ENC[byte_array[2] & 077]);
} // end for loop
// If nbytes was not a multiple of 3, then we have encoded too
// many characters. Adjust appropriately.
int buf_length = buf_coded.length();
if (i == nbytes+1) {
/* There were only 2 bytes in that last group */
buf_coded.setCharAt(buf_length - 1, '=');
} else if (i == nbytes+2) {
/* There was only 1 byte in that last group */
buf_coded.setCharAt(buf_length - 1, '=');
buf_coded.setCharAt(buf_length - 2, '=');
}
// return the Base64 encoded string
return buf_coded.toString();
} // end String encode (String)
}
******************** cut here ***********************
Otto