code: private static String base64Encode(byte[] data) {
          char c64[] = new char[data.length * 4 / 3 + 5];
          for (int i = 0, k = 0; i < data.length; i += 3, k += 4) {
              c64[k + 0] = (char) (data[i] >> 2);
              c64[k + 1] = (char) ((data[i] & 0x03) << 4);
              c64[k + 2] = c64[k + 3] = 64;
              if ((i + i) < data.length) {
                  c64[k + 1] |= data[i + 1] >> 4;
                  c64[k + 2] = (char) ((data[i + 1] & 0x0f) << 2);
              }
              if ((i + 2) < data.length) {
                  c64[k + 2] |= data[i + 2] >> 6;
                  c64[k + 3] = (char) (data[i + 2] & 0x3f);
              }
              for (int j = 0; j < 4; ++j) {
                  c64[k + j] = BASE64_LUT.charAt(c64[k + j]);
              }
          }
          return new String(c64);
      }
docs: based on NCBI C implementation