code: private static byte[] base64Decode(String data) {
          int len = data.length();
  
          byte[] b64 = new byte[len * 3 / 4];
          byte[] buf = new byte[4];
          boolean done = false;
  
          for (int i = 0, j, k = 0; i < len && !done;) {
              buf[0] = buf[1] = buf[2] = buf[3] = 0;
              for (j = 0; j < 4 && i < len; ++j) {
                  char c = data.charAt(i);
                  if (c >= 'A' && c <= 'Z') {
                      c -= 'A';
                  } else if (c >= 'a' && c <= 'z') {
                      c = (char) (c - 'a' + 26);
                  } else if (c >= '0' && c <= '9') {
                      c = (char) (c - '0' + 52);
                  } else if (c == '+') {
                      c = 62;
                  } else if (c == '/') {
                      c = 63;
                  } else if (c == '=' || c == '-') {
                      done = true;
                      break;
                  } else {
                      ++i;
                      --j;
                      continue;
                  }
                  buf[j] = (byte) c;
                  ++i;
              }
  
              if (k < b64.length && j >= 1) {
                  b64[k++] = (byte) ((buf[0] << 2) | ((buf[1] & 0x30) >> 4));
              }
              if (k < b64.length && j >= 3) {
                  b64[k++] = (byte) (((buf[1] & 0x0f) << 4) | ((buf[2] & 0x3c) >> 2));
              }
              if (k < b64.length && j >= 4) {
                  b64[k++] = (byte) (((buf[2] & 0x03) << 6) | (buf[3] & 0x3f));
              }
          }
          return b64;
      }
docs: based on NCBI C implementation