use of sun.misc.BASE64Decoder in project jdk8u_jdk by JetBrains.
the class SignatureAlgorithms method generateSSLContext.
private static SSLContext generateSSLContext(String trustedCertStr, String[] keyCertStrs, String[] keySpecStrs) throws Exception {
// generate certificate from cert string
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// create a key store
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
// import the trused cert
Certificate trusedCert = null;
ByteArrayInputStream is = null;
if (trustedCertStr != null) {
is = new ByteArrayInputStream(trustedCertStr.getBytes());
trusedCert = cf.generateCertificate(is);
is.close();
ks.setCertificateEntry("DSA Signer", trusedCert);
}
if (keyCertStrs != null && keyCertStrs.length != 0) {
for (int i = 0; i < keyCertStrs.length; i++) {
String keyCertStr = keyCertStrs[i];
String keySpecStr = keySpecStrs[i];
// generate the private key.
PKCS8EncodedKeySpec priKeySpec = new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(keySpecStr));
KeyFactory kf = KeyFactory.getInstance("DSA");
DSAPrivateKey priKey = (DSAPrivateKey) kf.generatePrivate(priKeySpec);
// generate certificate chain
is = new ByteArrayInputStream(keyCertStr.getBytes());
Certificate keyCert = cf.generateCertificate(is);
is.close();
Certificate[] chain = null;
if (trusedCert != null) {
chain = new Certificate[2];
chain[0] = keyCert;
chain[1] = trusedCert;
} else {
chain = new Certificate[1];
chain[0] = keyCert;
}
// import the key entry.
ks.setKeyEntry("DSA Entry " + i, priKey, passphrase, chain);
}
}
// create SSL context
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
tmf.init(ks);
SSLContext ctx = SSLContext.getInstance("TLS");
if (keyCertStrs != null && keyCertStrs.length != 0) {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509");
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
ks = null;
} else {
ctx.init(null, tmf.getTrustManagers(), null);
}
return ctx;
}
use of sun.misc.BASE64Decoder in project portal by ixinportal.
the class MakeInvoiceService method execute.
/**
* 开票推送
*/
@PostMapping(value = "/execute")
@ResponseBody
public Map<String, Object> execute(@RequestHeader("Content-Signature") String authHmac, @RequestParam("appId") String appId, @RequestParam("billId") String billNo, HttpServletRequest request) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("status", -2);
// 验证参数是否完整
if (StringUtils.isEmpty(authHmac) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(billNo)) {
result.put("message", "提交的参数信息不完整");
return result;
}
// 得到应用信息 改成service
Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
ApplicationInfo applicationInfo = appInfoMap.get(appId);
if (applicationInfo == null) {
ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
appInfoExampleCriteria.andAppIdEqualTo(appId);
applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
}
// 获取配置信息
ReceiptConfig rc = sqlSession.selectOne("com.itrus.portal.db.ReceiptConfigMapper.selectByExample");
log.debug("任务开始");
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus ts = null;
// 验证hmac有效性
try {
String macVal = Base64.encode(HMACSHA1.getHmacSHA1(appId + billNo, applicationInfo.getSecretKey()), false);
if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
result.put("status", -4);
result.put("message", "服务密钥错误");
return result;
}
} catch (Exception e) {
result.put("status", -3);
result.put("message", "Hmac验证错误");
e.printStackTrace();
return result;
}
try {
String ssl_store = getClass().getClassLoader().getResource("").getPath() + File.separator + // 执行命令后,会生成该testclient.truststore
"fapiao.truststore";
// 证书的存取密码,即执行命令时填写的密码
String ssl_pwd = "ixin21060921";
System.setProperty("javax.net.ssl.trustStore", ssl_store);
System.setProperty("javax.net.ssl.keyStorePassword", ssl_pwd);
// String url =
// "https://218.17.158.39:8999/fpt_dsqz/services/DZFPService?wsdl";
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
org.apache.axis.client.Service s = new org.apache.axis.client.Service();
Call call = (Call) s.createCall();
call.setTargetEndpointAddress(new URL(rc.getAddress()));
call.setOperation("doService");
Map param = new HashMap();
param.put("billNo", billNo);
Map<String, Object> data = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByBillEreceipt", param);
// Bill bill =sqlSession.selectOne("", billId);
String xml;
String val;
Bill bill;
Einvoice einvoice = null;
Ereceipt ereceipt;
Map<String, String> temp = null;
String content;
if (null != data && data.size() != 0) {
ereceipt = sqlSession.selectOne("com.itrus.portal.db.EreceiptMapper.selectByPrimaryKey", data.get("eid"));
content = getContent(data, ereceipt);
log.error("[input0]{}", content);
xml = getCommonXml("DFXJ1001", new BASE64Encoder().encodeBuffer(content.getBytes("UTF-8")), rc.getAppId());
log.error("[input1]{}", xml);
Object[] fn01 = { xml };
val = (String) call.invoke(fn01);
log.error("[output]{}", val);
temp = parseXml(val);
if (!temp.get("returnCode").equals("0000")) {
// LogUtil.syslog(sqlSession, "开票推送", data.get("bill_id") + "开票推送失败,错误:" + temp.get("returnMessage"));
log.error("ERRORLOG电子发票 {}", data.get("bill_id") + "开票推送失败,错误:" + temp.get("returnMessage"));
result.put("status", -1);
result.put("message", "开票推送失败");
return result;
}
temp = parseXml(new String(new BASE64Decoder().decodeBuffer(temp.get("content")), "UTF-8"));
einvoice = sqlSession.selectOne("com.itrus.portal.db.EinvoiceMapper.selectByPrimaryKey", data.get("e_invoice"));
einvoice.setInvoiceId(temp.get("FPQQLSH"));
einvoice.setInvoiceCode(temp.get("FP_DM"));
einvoice.setInvoiceNo(temp.get("FP_HM"));
einvoice.setCheckCode(temp.get("JYM"));
einvoice.setConfirmTime(sdf.parse(temp.get("KPRQ")));
einvoice.setDlAddress(temp.get("PDF_URL"));
einvoice.setStatus(1);
einvoice.setInvoiceSum(Double.valueOf(String.valueOf(data.get("bill_sum"))));
ts = transactionManager.getTransaction(def);
sqlSession.update("com.itrus.portal.db.EinvoiceMapper.updateByPrimaryKeySelective", einvoice);
bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", data.get("id"));
bill.setIsInvoiced(1);
bill.setBillTime(new Date());
if (null == bill.getDelivery() && bill.getBillStatus() == 6) {
bill.setBillStatus(ComNames.BILL_STATUS_8);
}
sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
transactionManager.commit(ts);
// count++;
result.put("status", 1);
result.put("address", temp.get("PDF_URL"));
}
// 返回地址
// LogUtil.syslog(sqlSession, "开票推送", "开票推送成功,推送" +
// billexall3.size() + "条,成功" + count + "条。");
log.debug("任务结束");
} catch (Exception e) {
// LogUtil.syslog(sqlSession, "开票推送", "开票推送失败,错误:" + e.toString());
log.error("ERRORLOG电子发票 {}", "开票推送失败,错误:" + e.toString());
e.printStackTrace();
} finally {
if (ts != null && !ts.isCompleted()) {
transactionManager.rollback(ts);
}
}
return result;
}
use of sun.misc.BASE64Decoder in project portal by ixinportal.
the class EvidenceSaveServiceApi method verifyTimeStamp.
/**
* 验时间戳接口
* @param authentication
* @param plainHash
* 时间戳数据
* @param hashAlg
* 原文的Hash结果
* @return
* @throws Exception
*/
public static org.json.JSONObject verifyTimeStamp(RealNameAuthentication authentication, String timeStamp, byte[] plainHash, String hashAlg) throws Exception {
if (authentication.getVersionNumber() == 1) {
byte[] tsaData = new BASE64Decoder().decodeBuffer(timeStamp);
String path = EvidenceSaveServiceApi.class.getClassLoader().getResource("").getPath() + File.separator + // 执行命令后,会生成该testclient.truststore
"tsCaCert.cer";
TsaVerifier.setCaCertByPath(path);
org.json.JSONObject json = TsaVerifier.verifyTimeStamp(tsaData, plainHash);
return json;
} else {
String url = authentication.getRealNameddress() + "/openapi/verify";
String hex = String.valueOf(HexUtils.encodeHex(plainHash));
String str = "{\"b64TimeStamp\":\"" + timeStamp + "\"," + "\"accessToken\":\"" + authentication.getAuthorizationCode() + "\"," + "\"hashAlg\":\"" + hashAlg + "\"," + "\"plainHash\":\"" + hex + "\"}";
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
String rep = HttpClientUtil.postForm(url, header, str);
org.json.JSONObject json = new org.json.JSONObject(rep);
return json;
}
}
use of sun.misc.BASE64Decoder in project portal by ixinportal.
the class UserInfoWebController method downloadEnclosure.
/**
* 下载附加文件
* @param productId
* @param request
* @param response
* @return
*/
@RequestMapping("/downloadEnclosure")
@ResponseBody
public synchronized Map<String, Object> downloadEnclosure(@RequestParam(value = "productId", required = true) Long productId, HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> retMap = new HashMap<String, Object>();
// 0标识失败,1标识成功
retMap.put("retCode", 0);
HttpSession session = request.getSession();
Boolean verifyCodeStatus = (Boolean) session.getAttribute("webverifyCodeStatus");
UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
if (null == verifyCodeStatus || !verifyCodeStatus || null == webuserInfo) {
// 登录状态失效,跳转到注册页面
// 2表示登录失效
retMap.put("retCode", 2);
retMap.put("retMsg", "登录已经失效,请重新登录");
return retMap;
}
try {
Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", productId);
if (product != null && product.getIsEnclosure() != null && product.getIsEnclosure() == 1) {
String url = null;
try {
url = systemConfigService.getEnclosureUrl();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String fileName = product.getEnclosureName();
fileName = encodeFilename(fileName, request);
response.reset();
response.addHeader("Content-Disposition", "attachment;filename=" + new String((fileName).getBytes("utf-8"), "iso-8859-1"));
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
String base64 = Base64Util.getBase64FromFile(url + "/" + product.getEnclosureName());
File file1 = new File(url + "/" + fileName);
if (base64 == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
// Base64解码
byte[] bytes = decoder.decodeBuffer(base64);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {
// 调整异常数据
bytes[i] += 256;
}
}
// 生成文件的路径
OutputStream out = /*new FileOutputStream(url+"/123.jpg");// 生成文件的路径*/
response.getOutputStream();
out.write(bytes);
out.flush();
out.close();
return null;
} else {
throw new TerminalServiceException("未上传附加");
}
// retMap.put("retCode", 1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TerminalServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of sun.misc.BASE64Decoder in project portal by ixinportal.
the class UserInfoWebController method enclosurefile.
/**
* 上传附加文件
* @param base64 文件base64
* @param files 文件类型
* @param productId 产品id
* @param response
* @param request
* @return
*/
@RequestMapping("/enclosurefile")
@ResponseBody
public synchronized Map<String, Object> enclosurefile(@RequestParam(value = "base64", required = false) String base64, @RequestParam(value = "files", required = false) Integer files, // @RequestParam(value = "projectId", required = true) Long projectId,
@RequestParam(value = "productId", required = false) Long productId, HttpServletResponse response, HttpServletRequest request) {
Map<String, Object> retMap = new HashMap<String, Object>();
// 0标识失败,1标识成功
retMap.put("retCode", 0);
HttpSession session = request.getSession();
Boolean verifyCodeStatus = (Boolean) session.getAttribute("webverifyCodeStatus");
UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
if (null == verifyCodeStatus || !verifyCodeStatus || null == webuserInfo) {
// 登录状态失效,跳转到注册页面
// 2表示登录失效
retMap.put("retCode", 2);
retMap.put("retMsg", "登录已经失效,请重新登录");
return retMap;
}
try {
Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", productId);
BASE64Decoder decoder = new BASE64Decoder();
byte[] bytes = decoder.decodeBuffer(base64);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {
// 调整异常数据
bytes[i] += 256;
}
}
System.out.println("files=" + files);
String zip = null;
String url = null;
if (files == 1) {
zip = ".jpg";
} else {
zip = ".zip";
}
try {
url = systemConfigService.getEnclosureUrl();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String name = null;
if (product.getEnclosureName().indexOf(".") > 0) {
name = product.getEnclosureName().substring(0, product.getEnclosureName().lastIndexOf("."));
}
System.out.println("name=" + name);
if (StringUtils.isEmpty(name)) {
name = product.getEnclosureName();
}
System.out.println(name);
// 生成文件的路径
OutputStream out = new FileOutputStream(url + "/" + name + zip);
System.out.println("url=" + url + name + zip);
out.write(bytes);
out.flush();
out.close();
product.setEnclosureName(name + zip);
product.setIsEnclosure(1);
sqlSession.update("com.itrus.portal.db.ProductMapper.updateByPrimaryKey", product);
retMap.put("retCode", 1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return retMap;
}
Aggregations