Example #1
0
 public static String decodeString(String encodedStr) {
   String encodeStr = "$#TGDF*FAA&21we@VGXD532w23413!";
   String tempStr = "";
   try {
     if (encodedStr == null) {
       encodedStr = "";
     }
     // encodedStr = new String(Hex.decodeHex(encodedStr.toCharArray()));
     Hex hex = new Hex();
     encodedStr = new String(hex.decode(encodedStr.getBytes("GBK")), "GBK");
     int i = 0;
     int j = 0;
     for (i = 0; i < encodedStr.length(); i++) {
       if (j >= encodeStr.length()) {
         j = 0;
       }
       char truePass = (char) ~(encodedStr.charAt(i) ^ ~encodeStr.charAt(j));
       tempStr = tempStr + truePass;
       j++;
     }
   } catch (Exception ex) {
     throw new RuntimeException(ex.getMessage());
   }
   return tempStr;
 }
Example #2
0
    @Override
    public void process(InputStream in, OutputStream out) throws IOException {
      int len;
      byte[] inBuf = new byte[8192];
      Hex h = new Hex();
      while ((len = in.read(inBuf)) > 0) {
        // If the input buffer is of odd length, try to get another byte
        if (len % 2 != 0) {
          int b = in.read();
          if (b != -1) {
            inBuf[len] = (byte) b;
            len++;
          }
        }

        // Construct a new buffer bounded to len
        byte[] slice = Arrays.copyOfRange(inBuf, 0, len);
        try {
          out.write(h.decode(slice));
        } catch (DecoderException ex) {
          throw new IOException(ex);
        }
      }
      out.flush();
    }