Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
  private static String signANDencrypt(MsgBean req_bean) {

    // 商户签名

    System.out.println("before sign xml ==" + req_bean.toSign());
    System.out.println("msg sign = " + RSA.sign(req_bean.toSign(), mer_pfx_key, mer_pfx_pass));
    req_bean.setMSG_SIGN(RSA.sign(req_bean.toSign(), mer_pfx_key, mer_pfx_pass));
    System.out.println("req:" + req_bean.toXml());

    // 加密报文
    String key = Util.generateKey(9999, 24);
    System.out.println("key:" + key);
    String req_body_enc = TripleDes.encrypt(key, req_bean.toXml());
    System.out.println("req_body_enc:" + req_body_enc);
    // 加密密钥
    String req_key_enc = RSA.encrypt(key, dna_pub_key);
    System.out.println("req_key_enc:" + req_key_enc);
    System.out.println("signANDencrypt:" + req_body_enc + "|" + req_key_enc);
    return req_body_enc + "|" + req_key_enc;
  }