public static String encode(byte data[])
{
return encode(data, 0, data.length);
}
public static String encode(byte data[], int off, int len)
{
if(len <= 0)
return " ";
char out[] = new char[(len / 3) * 4 + 4];
int rindex = off;
int windex = 0;
int rest;
for(rest = len - off; rest > = 3; rest -= 3)
{
int i = ((data[rindex] & 0xff) < < 16) + ((data[rindex + 1] & 0xff) < < 8) + (data[rindex + 2] & 0xff);
out[windex++] = S_BASE64CHAR[i > > 18];
out[windex++] = S_BASE64CHAR[i > > 12 & 0x3f];
out[windex++] = S_BASE64CHAR[i > > 6 & 0x3f];
out[windex++] = S_BASE64CHAR[i & 0x3f];
rindex += 3;
}
if(rest == 1)
{
int i = data[rindex] & 0xff;
out[windex++] = S_BASE64CHAR[i > > 2];
out[windex++] = S_BASE64CHAR[i < < 4 & 0x3f];
out[windex++] = '= ';
out[windex++] = '= ';
} else
if(rest == 2)
{