Exemplo n.º 1
0
 public static String decryptMoblie(String srcCode, String key) {
   String decCode = "";
   try {
     DES des = new DES(key);
     decCode = des.decrypt(srcCode);
   } catch (Exception e) {
     logger.error(e.getMessage());
   }
   return decCode;
 }
Exemplo n.º 2
0
 // 密码生成
 public static void main(String[] args) throws ErrMessage {
   DES des = new DES();
   String password = "******";
   String id = "admin";
   password = MD5.MD5(password);
   id = MD5.MD5(id);
   System.out.println(password);
   // 2.3DES加密
   password = des.enc3DES(id, password);
   System.out.println("密码:" + password);
   System.out.println("MD5:" + des.dec3DES(id, password));
 }
Exemplo n.º 3
0
  public static String getSolution(String sa0, int ia0) {
    String subKey = Utils.paddTo("0", 48);

    String b = DES.IP(sa0);
    String l = DES.getL(b);
    String r = DES.getR(b);

    for (int i = 0; i < ia0; i++) {
      String tmpR = r;
      r = DES.feistel(r, subKey);
      r = Utils.XOR(l, r);
      l = tmpR;
    }

    return r;
  }
Exemplo n.º 4
0
 /**
  * 以行为单位读取文件,进行解码
  *
  * @throws Exception
  */
 public static void readFileByLines(String fileName) throws Exception {
   File file = new File(fileName);
   BufferedReader reader = null;
   try {
     System.out.println("以行为单位读取文件内容,一次读一整行:");
     reader = new BufferedReader(new FileReader(file));
     String tempString = null;
     int line = 1;
     // 一次读入一行,直到读入null为文件结束
     while ((tempString = reader.readLine()) != null) {
       String uid = DES.decryptDES(KEY, replaceVVUID(tempString)).trim();
       System.out.println("line " + line + ": " + uid);
       line++;
     }
     reader.close();
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     if (reader != null) {
       try {
         reader.close();
       } catch (IOException e1) {
       }
     }
   }
 }
Exemplo n.º 5
0
  public Object makeKey(byte[] kb, int bs) throws InvalidKeyException {
    if (kb.length != KEY_SIZE) throw new InvalidKeyException("TripleDES key must be 24 bytes");

    if (!isParityAdjusted(kb, 0)) adjustParity(kb, 0);

    byte[] k1 = new byte[DES.KEY_SIZE], k2 = new byte[DES.KEY_SIZE], k3 = new byte[DES.KEY_SIZE];
    System.arraycopy(kb, 0, k1, 0, DES.KEY_SIZE);
    System.arraycopy(kb, DES.KEY_SIZE, k2, 0, DES.KEY_SIZE);
    System.arraycopy(kb, 2 * DES.KEY_SIZE, k3, 0, DES.KEY_SIZE);
    Context ctx = new Context();

    ctx.k1 = (DES.Context) des.makeKey(k1, bs);
    ctx.k2 = (DES.Context) des.makeKey(k2, bs);
    ctx.k3 = (DES.Context) des.makeKey(k3, bs);

    return ctx;
  }
Exemplo n.º 6
0
  public static void main(String[] args) throws Exception {

    // File directory = new File("");// 参数为空
    // String courseFile = directory.getCanonicalPath() +
    // File.separator+"vvtrackeruid.txt";
    // System.out.println(courseFile);
    //
    // try {
    // readFileByLines(courseFile);
    // } catch (Exception e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    String uid =
        DES.decryptDES(
                key2,
                replaceVVUID("H4sIAAAAAAAAA6WRubaiQABEc75icgKgu2kgmKBFNgWkAYFHxtYsPkRxAf3658x8"))
            .trim();
    System.out.println(uid);
  }
Exemplo n.º 7
0
  /**
   * Service.
   *
   * @param o the o
   * @param session the session
   */
  void service(IoBuffer o, IoSession session) {
    try {
      // System.out.println(o.remaining() + "/" + o.capacity());

      session.setAttribute("last", System.currentTimeMillis());

      SimpleIoBuffer in = (SimpleIoBuffer) session.getAttribute("buf");
      if (in == null) {
        in = SimpleIoBuffer.create(4096);
        session.setAttribute("buf", in);
      }
      byte[] data = new byte[o.remaining()];
      o.get(data);
      in.append(data);

      // log.debug("recv: " + data.length + ", " +
      // session.getRemoteAddress());

      while (in.length() > 5) {
        in.mark();
        /**
         * Byte 1: head of the package<br>
         * bit 7-6: "01", indicator of MDC<br>
         * bit 5: encrypt indicator, "0": no; "1": encrypted<br>
         * bit 4: zip indicator, "0": no, "1": ziped<br>
         * bit 0-3: reserved<br>
         * Byte 2-5: length of data<br>
         * Byte[…]: data array<br>
         */
        byte head = in.read();
        /** test the head indicator, if not correct close it */
        if ((head & 0xC0) != 0x40) {
          log.info("flag is not correct! flag:" + head + ",from: " + session.getRemoteAddress());

          session.close(true);
          return;
        }

        int len = in.getInt();

        if (len <= 0 || len > MAX_SIZE) {
          log.error(
              "mdcconnector.Wrong lendth: "
                  + len
                  + "/"
                  + MAX_SIZE
                  + " - "
                  + session.getRemoteAddress());
          session.close(true);
          break;
        }

        if (in.length() < len) {
          in.reset();
          break;
        } else {
          // do it
          // log.info("stub.package.size: " + len);

          byte[] b = new byte[len];
          in.read(b);

          if (TConn.DEBUG) {
            log.debug("recv: " + Bean.toString(b));
          }

          /** test the zip flag */
          if ((head & 0x10) > 0) {
            b = Zip.unzip(b);
          }

          final TConn d = (TConn) session.getAttribute("conn");
          if (d != null) {
            /** test the encrypted flag */
            if ((head & 0x20) > 0) {
              b = DES.decode(b, d.deskey);
            }

            final byte[] bb = b;
            /** test if the packet is for mdc or app */
            new WorkerTask() {

              @Override
              public void onExecute() {
                d.process(bb);
              }
            }.schedule(0);

            session.setAttribute("last", System.currentTimeMillis());
          }
        }
      }
    } catch (Throwable e) {
      log.error("closing stub: " + session.getRemoteAddress(), e);
      session.close(true);
    }
  }
Exemplo n.º 8
0
 String lameDecrypt(String ciphertext) {
   return DES.lameDecrypt(ciphertext, null);
 }
Exemplo n.º 9
0
 String lameEncrypt(String plaintext) {
   return DES.lameEncrypt(plaintext, null);
 }
Exemplo n.º 10
0
 public void decrypt(byte[] in, int i, byte[] out, int o, Object K, int bs) {
   byte[] temp = new byte[BLOCK_SIZE];
   des.decrypt(in, i, temp, 0, ((Context) K).k3, bs);
   des.encrypt(temp, 0, temp, 0, ((Context) K).k2, bs);
   des.decrypt(temp, 0, out, o, ((Context) K).k1, bs);
 }
Exemplo n.º 11
0
 /**
  * Tests if a byte array has already been parity adjusted.
  *
  * @param kb The key bytes to test.
  * @param offset The starting offset into the key bytes.
  * @return <code>true</code> if the bytes in <i>kb</i> starting at <i>offset</i> are parity
  *     adjusted.
  * @see DES#isParityAdjusted(byte[],int)
  * @see #adjustParity(byte[],int)
  */
 public static boolean isParityAdjusted(byte[] kb, int offset) {
   return DES.isParityAdjusted(kb, offset)
       && DES.isParityAdjusted(kb, offset + 8)
       && DES.isParityAdjusted(kb, offset + 16);
 }
Exemplo n.º 12
0
 /**
  * Transform a key so it will be parity adjusted.
  *
  * @param kb The key bytes to adjust.
  * @param offset The starting offset into the key bytes.
  * @see DES#adjustParity(byte[],int)
  */
 public static void adjustParity(byte[] kb, int offset) {
   DES.adjustParity(kb, offset);
   DES.adjustParity(kb, offset + 8);
   DES.adjustParity(kb, offset + 16);
 }