public static byte[] decode(byte[] bs)
  {
    int padding = 0;
    while (bs.length - padding > 0 && bs[bs.length - padding - 1] == 0x3d)
      {
        padding++;
      }
    int srclen = bs.length - padding; /* strip padding characters */
    byte[] buffer = new byte[(bs.length / 4) * 3 - padding]; /* target array */
    int buflen = 0;
    int si = 0;
    int len = srclen - si;
    while (len > 0)
      {
        byte b0 = dst[bs[si++] & 0xff];
        byte b2 = dst[bs[si++] & 0xff];
        buffer[buflen++] = (byte) (b0 << 2 & 0xfc | b2 >>> 4 & 0x3);
        if (len > 2)
          {
            b0 = b2;
            b2 = dst[bs[si++] & 0xff];
            buffer[buflen++] = (byte) (b0 << 4 & 0xf0 | b2 >>> 2 & 0xf);
            if (len > 3)
              {
                b0 = b2;
                b2 = dst[bs[si++] & 0xff];
                buffer[buflen++] = (byte) (b0 << 6 & 0xc0 | b2 & 0x3f);
              }
          }
        len = srclen - si;
      }
    return buffer;
  }