static public char[] encode(byte[] data)
	{
		char[] out = new char[((data.length + 2) / 3) * 4];

		//
		// 3 bytes encode to 4 chars.  Output is always an even
		// multiple of 4 characters.
		//
		for (int i=0, index=0; i<data.length; i+=3, index+=4) {
			boolean quad = false;
			boolean trip = false;

			int val = (0xFF & (int) data[i]);
			val <<= 8;
			if ((i+1) < data.length) {
				val |= (0xFF & (int) data[i+1]);
				trip = true;
			}
			val <<= 8;
			if ((i+2) < data.length) {
				val |= (0xFF & (int) data[i+2]);
				quad = true;
			}
			out[index+3] = alphabet[(quad? (val & 0x3F): 64)];
			val >>= 6;
			out[index+2] = alphabet[(trip? (val & 0x3F): 64)];
			val >>= 6;
			out[index+1] = alphabet[val & 0x3F];
			val >>= 6;
			out[index] = alphabet[val & 0x3F];
		}
		return out;
	}