public static String zip(String param) { try { byte[] unzip = param.getBytes("UTF-8"); ByteArrayInputStream bif = new ByteArrayInputStream(unzip); ByteArrayOutputStream zipbof = new ByteArrayOutputStream(); // DeflaterOutputStream dos = new DeflaterOutputStream(zipbof); GZIPOutputStream gos = new GZIPOutputStream(zipbof); int position = 0; for (int read_byte = 0; (read_byte = bif.read()) != -1; position++) { // dos.write(read_byte); gos.write(read_byte); } // dos.finish(); gos.finish(); zipbof.flush(); byte[] zipbyteArray = zipbof.toByteArray(); // return new sun.misc.BASE64Encoder().encode(zipbyteArray); return Base64.encodeBase64String(zipbyteArray); } catch (Exception ex) { return null; } }
private BasicCredentials(String aMethod, String aUsername, String aPassword) { method = aMethod; username = aUsername; password = aPassword; String userCredentials = username + ":" + password; byte[] credentialsBytes = userCredentials.getBytes(B2CConverter.ISO_8859_1); String base64auth = Base64.encodeBase64String(credentialsBytes); credentials = method + " " + base64auth; }
public String EncryptText(String RawText) { String EncText = ""; byte[] keyArray = new byte[24]; byte[] temporaryKey; String key = "developersnotedotcom"; byte[] toEncryptArray = null; try { toEncryptArray = RawText.getBytes("UTF-8"); MessageDigest m = MessageDigest.getInstance("MD5"); temporaryKey = m.digest(key.getBytes("UTF-8")); if (temporaryKey.length < 24) // DESede require 24 byte length key { int index = 0; for (int i = temporaryKey.length; i < 24; i++) { keyArray[i] = temporaryKey[index]; } } Cipher c = Cipher.getInstance("DESede/CBC/PKCS5Padding"); c.init( Cipher.ENCRYPT_MODE, new SecretKeySpec(keyArray, "DESede"), new IvParameterSpec(sharedvector)); byte[] encrypted = c.doFinal(toEncryptArray); EncText = Base64.encodeBase64String(encrypted); } catch (NoSuchAlgorithmException | UnsupportedEncodingException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException NoEx) { JOptionPane.showMessageDialog(null, NoEx); } return EncText; }
public Result send(CouponReqVO couponReq, HttpServletRequest request, boolean isReal) { SendVO sendVO = new SendVO(); if (couponReq.getMid() == null || couponReq.getPassword() == null) { return new Result(100, "필수파라메터 부족"); } // 판매업체 mid와 password가 일치하는지 확인 SellerVO inSeller = new SellerVO(); inSeller.setMid(couponReq.getMid()); inSeller.setPassword(couponReq.getPassword()); SellerVO seller = adminService.getSeller(inSeller); if (seller == null) { return new Result(200, "등록된 판매업체가 아닙니다."); } sendVO.setSeller_id(seller.getSeller_id()); // 등록된 IP인지 확인 String allowed_ip = seller.getAllowed_ip(); if (!allowed_ip.contains(request.getRemoteAddr())) { logger.debug("ip:" + request.getRemoteAddr()); return new Result(300, "허용된 IP가 아닙니다."); } // 상품 정보 확인 GoodsVO inGoods = new GoodsVO(); inGoods.setGoods_code(couponReq.getGoods_code()); inGoods.setReal(isReal); // 실상품 or 테스트 상품 구분 GoodsVO goods = adminService.getGoods(inGoods); if (goods == null) { return new Result(400, "등록된 상품코드가 아닙니다."); } sendVO.setGoods_id(goods.getGoods_id()); // 판매가격은 상품정보의 sell_price로 세팅. 판매업체에게 제공받지 않는다. sendVO.setSell_price(goods.getSell_price()); // 발송정보 세팅 sendVO.setGoods_count("1"); // 상품 수량은 1로 고정 sendVO.setRecv_phone(couponReq.getRecv_phone()); sendVO.setSend_phone(couponReq.getSend_phone()); sendVO.setTr_id(couponReq.getTr_id()); sendVO.setMsg(couponReq.getMessage()); restTemplate = new RestTemplate(); params = new LinkedMultiValueMap<String, String>(); UriComponents uriComponents; String baseUrl = ""; // M12 handling if (goods.getProvider() == 1) { params.add("goods_code", couponReq.getGoods_code()); params.add("goods_count", sendVO.getGoods_count()); // 상품 수량 1로 고정 params.add("send_phone", couponReq.getSend_phone()); params.add("recv_phone", couponReq.getRecv_phone()); params.add("tr_id", couponReq.getTr_id()); params.add("userid", "hlint"); params.add("sell_price", sendVO.getSell_price()); // 상품 판매가격으로 고정 params.add("msg", couponReq.getMessage()); if (isReal) { baseUrl = "http://web6.m12.co.kr:12101/app/order_send.php"; } else { baseUrl = "http://web6.m12.co.kr:12101/app/dev/order_send.php"; } uriComponents = UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(params).build(); String value = uriComponents.getQuery(); String key = "HLINTNLE54A3I2O1"; String initVector = "J0S9O8T7USJFDLSX"; logger.debug(value); try { IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] encrypted = cipher.doFinal(value.getBytes()); String strpara = Base64.encodeBase64String(encrypted); params.clear(); params.add("marketcode", "HLINTNL01"); params.add("strpara", strpara); uriComponents = UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(params).build(); logger.debug(uriComponents.toUriString()); String strResult = restTemplate.getForObject(uriComponents.toUriString(), String.class); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(new StringReader(strResult)); Element rootNode = document.getRootElement(); logger.debug(rootNode.getName()); String resultCode = rootNode.getChild("RESULT_CODE", rootNode.getNamespace()).getText(); String statusCode = rootNode.getChild("STATUS_CODE", rootNode.getNamespace()).getText(); // 쿠폰 발송 상태 저장 sendVO.setResult_code(resultCode); sendVO.setStatus_code(statusCode); sendVO.setReal(isReal); logger.debug(sendVO.toString()); adminService.addSend(sendVO); return new Result(Integer.parseInt(resultCode), statusCode); } catch (Exception e) { e.printStackTrace(); return new Result(500, "내부 오류가 발생하였습니다."); } } // Coup handling, 문서 2.18 구현 else if (goods.getProvider() == 2) { params.add("CODE", "0424"); params.add("PASS", "hlint123"); params.add("COUPONCODE", couponReq.getGoods_code()); params.add("SEQNUMBER", couponReq.getTr_id()); params.add("QTY", sendVO.getGoods_count()); // 상품수량은 1개 params.add("HP", couponReq.getRecv_phone()); params.add("CALLBACK", couponReq.getSend_phone()); params.add("TITLE", ""); params.add("ADDMSG", couponReq.getMessage()); params.add("SELPRICE", sendVO.getSell_price()); // 상품 가격 세팅 // logger.debug(params.toString()); if (isReal) { baseUrl = "http://v3api.inumber.co.kr/serviceapi_02.asmx/ServiceCreateSendMuch"; } else { baseUrl = "http://issuev3apitest.m2i.kr:9999/serviceapi_02.asmx/ServiceCreateSendMuch"; } try { uriComponents = UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(params).build(); logger.debug(uriComponents.toUriString()); String strResult = restTemplate.getForObject(uriComponents.toUriString(), String.class); logger.debug("strResult:" + strResult); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(new StringReader(strResult)); Element rootNode = document.getRootElement(); String resultCode = rootNode.getChild("RESULTCODE", rootNode.getNamespace()).getText(); String resultMsg = rootNode.getChild("RESULTMSG", rootNode.getNamespace()).getText(); // 쿠폰 발송 상태 저장 sendVO.setResult_code(resultCode); sendVO.setStatus_code(resultMsg); // 쿠폰번호와 핀번호 저장 if ("00".equals(resultCode)) { Element List = rootNode.getChild("LIST", rootNode.getNamespace()); List couponList = List.getChildren("GCOUPONLIST", rootNode.getNamespace()); // 한건만 보내므로 루프를 돌리지않고 한건만 저장 Element node = (Element) couponList.get(0); String couponNumber = node.getChildText("COUPONNUMBER", rootNode.getNamespace()); String pinNumber = node.getChildText("PINNUMBER", rootNode.getNamespace()); sendVO.setCouponnumber(couponNumber); sendVO.setPinnumber(pinNumber); } sendVO.setReal(isReal); logger.debug(sendVO.toString()); adminService.addSend(sendVO); return new Result(Integer.parseInt(resultCode), resultMsg); } catch (Exception e) { e.printStackTrace(); return new Result(100, "Coupon failed"); } } return new Result(500, "내부 오류가 발생하였습니다."); }
public static String getSalt() { Random r = new SecureRandom(); byte[] saltBytes = new byte[32]; r.nextBytes(saltBytes); return Base64.encodeBase64String(saltBytes); }
@Override public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException { if (checkForCachedAuthentication(request, response, true)) { return true; } MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders().getValue("authorization"); if (authorization == null) { if (log.isDebugEnabled()) { log.debug(sm.getString("authenticator.noAuthHeader")); } response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } authorization.toBytes(); ByteChunk authorizationBC = authorization.getByteChunk(); if (!authorizationBC.startsWithIgnoreCase("negotiate ", 0)) { if (log.isDebugEnabled()) { log.debug(sm.getString("spnegoAuthenticator.authHeaderNotNego")); } response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } authorizationBC.setOffset(authorizationBC.getOffset() + 10); byte[] decoded = Base64.decodeBase64( authorizationBC.getBuffer(), authorizationBC.getOffset(), authorizationBC.getLength()); if (getApplyJava8u40Fix()) { SpnegoTokenFixer.fix(decoded); } if (decoded.length == 0) { if (log.isDebugEnabled()) { log.debug(sm.getString("spnegoAuthenticator.authHeaderNoToken")); } response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } LoginContext lc = null; GSSContext gssContext = null; byte[] outToken = null; Principal principal = null; try { try { lc = new LoginContext(getLoginConfigName()); lc.login(); } catch (LoginException e) { log.error(sm.getString("spnegoAuthenticator.serviceLoginFail"), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return false; } Subject subject = lc.getSubject(); // Assume the GSSContext is stateless // TODO: Confirm this assumption final GSSManager manager = GSSManager.getInstance(); // IBM JDK only understands indefinite lifetime final int credentialLifetime; if (Globals.IS_IBM_JVM) { credentialLifetime = GSSCredential.INDEFINITE_LIFETIME; } else { credentialLifetime = GSSCredential.DEFAULT_LIFETIME; } final PrivilegedExceptionAction<GSSCredential> action = new PrivilegedExceptionAction<GSSCredential>() { @Override public GSSCredential run() throws GSSException { return manager.createCredential( null, credentialLifetime, new Oid("1.3.6.1.5.5.2"), GSSCredential.ACCEPT_ONLY); } }; gssContext = manager.createContext(Subject.doAs(subject, action)); outToken = Subject.doAs(lc.getSubject(), new AcceptAction(gssContext, decoded)); if (outToken == null) { if (log.isDebugEnabled()) { log.debug(sm.getString("spnegoAuthenticator.ticketValidateFail")); } // Start again response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } principal = Subject.doAs( subject, new AuthenticateAction(context.getRealm(), gssContext, storeDelegatedCredential)); } catch (GSSException e) { if (log.isDebugEnabled()) { log.debug(sm.getString("spnegoAuthenticator.ticketValidateFail"), e); } response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); if (cause instanceof GSSException) { if (log.isDebugEnabled()) { log.debug(sm.getString("spnegoAuthenticator.serviceLoginFail"), e); } } else { log.error(sm.getString("spnegoAuthenticator.serviceLoginFail"), e); } response.setHeader("WWW-Authenticate", "Negotiate"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; } finally { if (gssContext != null) { try { gssContext.dispose(); } catch (GSSException e) { // Ignore } } if (lc != null) { try { lc.logout(); } catch (LoginException e) { // Ignore } } } // Send response token on success and failure response.setHeader("WWW-Authenticate", "Negotiate " + Base64.encodeBase64String(outToken)); if (principal != null) { register(request, response, principal, Constants.SPNEGO_METHOD, principal.getName(), null); Pattern p = noKeepAliveUserAgents; if (p != null) { MessageBytes ua = request.getCoyoteRequest().getMimeHeaders().getValue("user-agent"); if (ua != null && p.matcher(ua.toString()).matches()) { response.setHeader("Connection", "close"); } } return true; } response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return false; }