public static String encode(String str) {
        sb.delete(0, sb.length());
        final byte[] str_b = str.getBytes();
        final int div = 3 - (str_b.length % 3);
        final byte[] data = new byte[str_b.length + div];

        for (int i = 0; i < str_b.length; i++) {
            data[i] = str_b[i];
        }
        int tmp;
        for (int i = 0; i < str_b.length; i += 3) {
            tmp = (data[i] << 16) | (data[i + 1] << 8) | data[i + 2];
            sb.append(encode_table[(tmp >> 18) & 0x3f]);
            sb.append(encode_table[(tmp >> 12) & 0x3f]);
            sb.append(encode_table[(tmp >> 6) & 0x3f]);
            sb.append(encode_table[(tmp >> 0) & 0x3f]);
        }
        if (div < 3) {
            sb.delete(sb.length() - div, sb.length());
            for (int j = 0; j < div; j++) {
                sb.append('=');
            }
        }
        return sb.toString();
    }