Ejemplo n.º 1
0
  public static String sendAndRead(String req) {

    try {
      HttpURLConnection connect = new SslConnection().openConnection(url);

      connect.setReadTimeout(30000);
      connect.setConnectTimeout(10000);

      connect.setRequestMethod("POST");
      connect.setDoInput(true);
      connect.setDoOutput(true);
      connect.connect();

      byte[] put = req.getBytes("UTF-8");
      connect.getOutputStream().write(put);

      connect.getOutputStream().flush();
      connect.getOutputStream().close();
      String res = SslConnection.read(connect);

      connect.getInputStream().close();
      connect.disconnect();

      //			String res = new SslConnection().connect(url);

      return res;
    } catch (Exception e) {
      logger.error(Strings.getStackTrace(e));
    }
    return "";
  }
Ejemplo n.º 2
0
  private static MsgBean decryptANDverify(String res) {

    String msg_sign_enc = res.split("\\|")[0];
    String key_3des_enc = res.split("\\|")[1];

    // 解密密钥
    String key_3des = RSA.decrypt(key_3des_enc, mer_pfx_key, mer_pfx_pass);

    // 解密报文
    String msg_sign = TripleDes.decrypt(key_3des, msg_sign_enc);
    MsgBean res_bean = new MsgBean();
    res_bean.toBean(msg_sign);
    System.out.println("res:" + res_bean.toXml());

    // 验签
    String dna_sign_msg = res_bean.getMSG_SIGN();
    res_bean.setMSG_SIGN("");
    String verify =
        Strings.isNullOrEmpty(res_bean.getVERSION()) ? res_bean.toXml() : res_bean.toSign();
    System.out.println("verify:" + verify);
    if (!RSA.verify(dna_sign_msg, dna_pub_key, verify)) {
      logger.error("验签失败");
      res_bean.setTRANS_STATE("00A0");
    }
    return res_bean;
  }