List of usage examples for org.bouncycastle.util.encoders Hex encode
public static byte[] encode(byte[] data)
From source file:NaverShopnCancelReturn.java
/** * /*from www . jav a 2s .c o m*/ * @param serviceName * @param operationName * @throws Exception */ public void encryptInit(String serviceName, String operationName) throws Exception { this.setServiceName(serviceName); this.setOperationName(operationName); Security.addProvider(new BouncyCastleProvider()); this.setTimestamp(SimpleCryptLib.getTimestamp()); this.setData(this.getTimestamp() + this.getServiceName() + this.getOperationName()); //generateSign this.setSignature(SimpleCryptLib.generateSign(this.getData(), this.getSecretKey())); //generateKey this.setEncryptKey(SimpleCryptLib.generateKey(this.getTimestamp(), this.getSecretKey())); //encrypt this.setEncryptedData(SimpleCryptLib.encrypt(this.getEncryptKey(), this.getPassword().getBytes("UTF-8"))); this.setDecryptedData( new String(SimpleCryptLib.decrypt(this.getEncryptKey(), this.getEncryptedData()), "UTF-8")); this.setHashedData(SimpleCryptLib.sha256(this.getPassword())); System.out.println("accessLicense : [" + this.getAccessLicense() + "]"); System.out.println("secretKey : [" + this.getSecretKey() + "]"); System.out.println("serviceName : [" + this.getServiceName() + "]"); System.out.println("operationName : [" + this.getOperationName() + "]"); System.out.println("timestamp : [" + this.getTimestamp() + "]"); System.out.println("signature : [" + this.getSignature() + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(this.getEncryptKey())) + "]"); System.out.println("encryptedData : [" + this.getEncryptedData() + "]"); System.out.println("decryptedData : [" + this.getDecryptedData() + "]"); System.out.println("sha256Data : [" + this.getHashedData() + "]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); }
From source file:NaverCheckOutGetOrder.java
public String run() { String response_type = "FALSE"; try {/* www . j a v a2s . c o m*/ SimpleCryptLib SimpleCryptLib = new SimpleCryptLib(); Security.addProvider(new BouncyCastleProvider()); // String accessLicense = "0100010000ccc831f99d7d2523deadf954c8459d6b671b20006e221f64c45dea503be632be"; // String secretKey = "AQABAACDZOhE97kLH8iavhKiQCHbCGlfQfqCSGRxDlAV6uddcg=="; String accessLicense = "0100010000a3a4a4365b74db9433a0971c8f85f2de07661a6338b6bb9c2155a2fc892d4ff5"; String secretKey = "AQABAADe1F8bpQsO4ORdqfzpIj2Fl5YwstWww9JGEUNLxU78Dg=="; String serviceName = "MallService2"; String id = "wjsgnsvy"; String password = "jhp1229"; String timestamp = null; String signature = null; String data = null; byte[] encryptKey = null; String encryptedData = null; String decryptedData = null; String hashedData = null; String operationName = "GetPaidOrderList"; //String orderID = "200087036"; //timestamp create timestamp = SimpleCryptLib.getTimestamp(); System.out.println("timestamp:" + timestamp); //generateSign data = timestamp + serviceName + operationName; signature = SimpleCryptLib.generateSign(data, secretKey); //generateKey encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey); //encrypt encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8")); //decrypt decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8"); //sha256 hashedData = SimpleCryptLib.sha256(password); NaverCheckOutGetOrder NaverCheckOutGetOrder = new NaverCheckOutGetOrder(); System.out.println("NaverCheckOutGetOrder.getYesterday():" + NaverCheckOutGetOrder.getYesterday()); System.out.println("NaverCheckOutGetOrder.getYesterday():" + NaverCheckOutGetOrder.getToday()); System.out.println("accessLicense : [" + accessLicense + "]"); System.out.println("secretKey : [" + secretKey + "]"); System.out.println("serviceName : [" + serviceName + "]"); System.out.println("operationName : [" + operationName + "]"); System.out.println("timestamp : [" + timestamp + "]"); System.out.println("signature : [" + signature + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]"); System.out.println("encryptedData : [" + encryptedData + "]"); System.out.println("decryptedData : [" + decryptedData + "]"); System.out.println("sha256Data : [" + hashedData + "]"); /*String xmldata = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mall=\"http://mall.checkout.platform.nhncorp.com/\" xmlns:base=\"http://base.checkout.platform.nhncorp.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<mall:GetOrderInfoRequest>" + "<base:RequestID>?</base:RequestID>" + "<base:AccessCredentials>" + "<base:AccessLicense>"+ accessLicense +"</base:AccessLicense>" + "<base:Timestamp>"+ timestamp +"</base:Timestamp>" + "<base:Signature>"+ signature +"</base:Signature>" + "</base:AccessCredentials>" + "<base:DetailLevel>Full</base:DetailLevel>" + //<!-- value Full, Compact ) "<base:Version>2.0</base:Version>" + "<OrderID>"+ orderID +"</OrderID>" + "</mall:GetOrderInfoRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>";*/ System.out.println("NaverCheckOutGetOrder.getYesterday():" + NaverCheckOutGetOrder.getYesterday()); System.out.println("NaverCheckOutGetOrder.getToday():" + NaverCheckOutGetOrder.getToday()); String orderlist = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mall=\"http://mall.checkout.platform.nhncorp.com/\" xmlns:base=\"http://base.checkout.platform.nhncorp.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<mall:GetPaidOrderListRequest>" + "<base:RequestID>?</base:RequestID>" + "<base:AccessCredentials>" + "<base:AccessLicense>" + accessLicense + "</base:AccessLicense>" + "<base:Timestamp>" + timestamp + "</base:Timestamp>" + "<base:Signature>" + signature + "</base:Signature>" + "</base:AccessCredentials>" + "<base:DetailLevel>Full</base:DetailLevel>" + "<base:Version>2.0</base:Version>" + "<base:InquiryTimeFrom>" + NaverCheckOutGetOrder.getYesterday() + "</base:InquiryTimeFrom>" + //NaverCheckOutGetOrder.getYesterday() //2011-05-06T00:00:04.662Z "<base:InquiryTimeTo>" + NaverCheckOutGetOrder.getToday() + "</base:InquiryTimeTo>" + //NaverCheckOutGetOrder.getToday() //2011-05-06T23:00:04.662Z "</mall:GetPaidOrderListRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"; //2011-07-29T04:33:52.881Z //Create socket //String hostname = "ec.api.naver.com"; String hostname = "api.naver.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/Checkout/MallService2"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0 \r\n"); //wr.write("Host: ec.api.naver.com \r\n"); wr.write("Host: api.naver.com \r\n"); //wr.write("Content-Length: " + xmldata.length() + "\r\n"); wr.write("Content-Length: " + orderlist.length() + "\r\n"); wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n"); //wr.write("SOAPAction: \"http://ec.api.naver.com/Checkout/MallService2\" \r\n"); wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n"); wr.write("\r\n"); //Send data //wr.write(xmldata); wr.write(orderlist); wr.flush(); // InputStream test = new InputStream(sock.getInputStream(),"UTF-8"); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")); String line = ""; String line_total = ""; String tmp = ""; String tmp2 = ""; String newxml = ""; /*while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ line = line.replaceAll("
", " "); line_total= line_total + line ; System.out.println(line); } }*/ StringBuffer sf = new StringBuffer(); /* while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ sf.append(line+"\n"); // . } }*/ char[] bufferResult = new char[1048576]; int index = -1; while ((index = rd.read(bufferResult)) != -1) { sf.append(bufferResult, 135, index); //response 133 135 } line_total = sf.toString().trim(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); line_total = line_total.replaceAll("n1:", ""); System.out.println(line_total); //xml2 InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8")); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); Element element = document.getRootElement(); List envel_list = element.getChildren(); List body_list = null; List body_list1 = null; List result_list = null; List result_list1 = null; List result_list2 = null; List result_list3 = null; List result_list4 = null; List result_list5 = null; List info_list = null; List contr_group_list = null; List contr_info_list = null; StringBuffer selectChk = new StringBuffer(); selectChk.append(" select count(*) cnt \n"); selectChk.append(" from ktc_njoyny_hmall_if \n"); selectChk.append(" where h_order_no = ? and coven_id = 26050 \n"); String getInterfacedata = " select UNIT_ID,ITEM_ID " + " from ( " + " select item_id, " + " UNIT_name, " + " decode(( " + " select count(*) cnt " + " from ktc_unit " + " where item_id = ? " + " group by item_id), 1, UNIT_id, decode(trim(UNIT_NAME) ,trim(?), UNIT_id, '')) UNIT_id " + " from ktc_unit " + " where item_id = ? ) " + " where unit_id is not null "; PreparedStatement pstmt = null; ResultSet rs = null; CallableStatement cStmt = null; System.out.println("DBconnect"); //conn.setAutoCommit(false); long UNIT_ID = 0; long cnt = 0; long interface_seq = 0; long DEL_QTY = 0; long ITEM_ID = 0; String ITEM_NAME = null; System.out.println("envel_list.size:" + envel_list.size()); Element envel_el = (Element) envel_list.get(0); body_list = envel_el.getChildren(); System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren()); System.out.println("body_list.size:" + body_list.size()); Element body_el = (Element) body_list.get(0); result_list = body_el.getChildren("PaidOrderList"); System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren()); for (int h = 0; h < result_list.size(); h++) { System.out.println("$$111$$"); Element body_el1 = (Element) result_list.get(h); System.out.println("$$222$$"); result_list1 = body_el1.getChildren("PaidOrder"); System.out.println("result_list1.size:" + result_list1.size()); System.out.println("$$333$$"); System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren()); for (int i = 0; i < result_list1.size(); i++) { System.out.println("$$4444$$" + result_list1.size()); Element body_el2 = (Element) result_list1.get(i); result_list2 = body_el2.getChildren("Order"); Element body_el3 = (Element) result_list1.get(i); result_list3 = body_el3.getChildren("OrderProductList"); Element body_el4 = (Element) result_list1.get(i); result_list4 = body_el4.getChildren("Shipping"); for (int j = 0; j < result_list2.size(); j++) { Element body_el5 = (Element) result_list2.get(j);// Element body_el7 = (Element) result_list4.get(j);// Element body_el8 = (Element) result_list3.get(j); result_list5 = body_el8.getChildren("OrderProduct");// //result_list5 = (Element) result_list3.get(j);// System.out.println("$$55555$$"); if (body_el5.getChildText("OrderStatusCode").equals("OD0002")) {// pstmt = conn.prepareStatement(selectChk.toString()); pstmt.setString(1, body_el5.getChildText("OrderID")); rs = pstmt.executeQuery(); if (rs.next()) { cnt = rs.getLong("cnt"); } System.out.println(" cnt:" + cnt); if (rs != null) { try { rs.close(); } catch (Exception e) { response_type = "FALSE"; } } if (pstmt != null) { try { pstmt.close(); } catch (Exception e) { response_type = "FALSE"; } } System.out.println("result_list5.size():" + result_list5.size()); for (int k = 0; k < result_list5.size(); k++) { Element body_el9 = (Element) result_list5.get(k); ITEM_NAME = body_el9.getChildText("ProductName"); DEL_QTY = Long.parseLong(body_el9.getChildText("Quantity")); pstmt = conn.prepareStatement(getInterfacedata); System.out.println("body_el9.getChildText:" + body_el9.getChildText("ProductID")); System.out .println("body_el9.getChildText:" + body_el9.getChildText("ProductOption")); pstmt.setLong(1, Long.parseLong(body_el9.getChildText("ProductID"))); pstmt.setString(2, body_el9.getChildText("ProductOption")); pstmt.setLong(3, Long.parseLong(body_el9.getChildText("ProductID"))); rs = pstmt.executeQuery(); if (rs.next()) { UNIT_ID = rs.getLong("UNIT_ID"); ITEM_ID = rs.getLong("ITEM_ID"); //DEL_QTY = rs.getLong("DEL_QTY"); } System.out.println("UNIT_ID:" + UNIT_ID); System.out.println("ITEM_ID:" + ITEM_ID); System.out.println("ITEM_NAME:" + ITEM_NAME); if (rs != null) { try { rs.close(); } catch (Exception e) { response_type = "FALSE"; } } if (pstmt != null) { try { pstmt.close(); } catch (Exception e) { response_type = "FALSE"; } } } // 1 . System.out.println("1111 333331"); String getInterfaceSeq = " select ktc_njoyny_hmall_if_seq.nextval interfaceSeq from dual "; pstmt = conn.prepareStatement(getInterfaceSeq); rs = pstmt.executeQuery(); if (rs.next()) { interface_seq = rs.getLong("interfaceSeq"); } System.out.println("+ interface_seq [" + interface_seq + "]"); if (rs != null) { try { rs.close(); } catch (Exception e) { response_type = "FALSE"; } } if (pstmt != null) { try { pstmt.close(); } catch (Exception e) { response_type = "FALSE"; } } if (cnt == 0) { // .. System.out.println("body_el5.getChildText:" + body_el5.getChildText("OrderID")); if (NaverCheckOutGetOrder.run2(body_el5.getChildText("OrderID")) .equals("SUCCESS")) {// StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into ktc_njoyny_hmall_if( \n"); setOrder.append(" h_order_no, seq, order_date, recv_date, item_id, \n"); setOrder.append(" unit_id, item_name, price, qty, orderer_name, \n"); setOrder.append( " orderer_phone, orderer_cell_phone, orderer_eng_name, orderer_resi_no, orderer_email, \n"); setOrder.append( " msg_for_mall, del_plan_date, receiver_name, receiver_phone, receiver_cell_phone, \n"); setOrder.append( " receiver_zip_code, receiver_addr1, receiver_addr2, msg_for_outbnd, interface_date, \n"); setOrder.append(" interface_seq, sysregdt, coven_id \n"); setOrder.append(" ) values ( \n"); setOrder.append( " 'naver_'||?, ktc_njoyny_hmall_if_seq.nextval, to_date(?,'yyyy/mm/dd hh24:mi:ss'), sysdate, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, sysdate+5, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, sysdate, \n"); setOrder.append(" ?, sysdate, ? \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setLong(1, Long.parseLong(body_el5.getChildText("OrderID"))); // h_order_no System.out.println(body_el5.getChildText("OrderID")); pstmt.setString(2, body_el5.getChildText("OrderDateTime").substring(0, 10)); //order_date System.out.println(body_el5.getChildText("OrderDateTime").substring(0, 10)); pstmt.setLong(3, ITEM_ID); // item_id System.out.println(ITEM_ID); pstmt.setLong(4, UNIT_ID); // unit_id System.out.println(UNIT_ID); pstmt.setString(5, ITEM_NAME); // ITEM_NAME System.out.println(ITEM_NAME); pstmt.setLong(6, Long.parseLong(body_el5.getChildText("TotalProductAmount"))); //price -> 0.95 + + System.out.println( Long.parseLong(body_el5.getChildText("TotalProductAmount"))); pstmt.setLong(7, DEL_QTY); //qty System.out.println(DEL_QTY); pstmt.setString(8, new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); // orderer_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); pstmt.setString(9, NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererTel")), "UTF-8"))); //orderer_phone System.out .println( NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib .decrypt(encryptKey, body_el5.getChildText( "OrdererTel")), "UTF-8"))); pstmt.setString(10, NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererTel")), "UTF-8"))); // orderer_cell_phone pstmt.setString(11, null); // orderer_eng_name pstmt.setString(12, null); // orderer_resi_no pstmt.setString(13, null); // orderer_email pstmt.setString(14, body_el7.getChildText("ShippingMessage")); // msg_for_mall pstmt.setString(15, new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("Recipient")), "UTF-8")); // receiver_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("Recipient")), "UTF-8")); pstmt.setString(16, NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_phone System.out .println( NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText( "RecipientTel1")), "UTF-8"))); pstmt.setString(17, NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_cell_phone System.out .println( NaverCheckOutGetOrder .getTel(new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText( "RecipientTel1")), "UTF-8"))); pstmt.setString(18, body_el7.getChildText("ZipCode")); //receiver_zip_code pstmt.setString(19, new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress1")), "UTF-8")); //receiver_addr1 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress1")), "UTF-8")); pstmt.setString(20, new String( SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress2")), "UTF-8")); //receiver_addr2 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress2")), "UTF-8")); pstmt.setString(21, body_el7.getChildText("ShippingMessage")); // msg_for_outbnd System.out.println(body_el7.getChildText("ShippingMessage")); pstmt.setLong(22, interface_seq); // interface_seq pstmt.setString(23, "26050"); // coven_id pstmt.executeUpdate(); System.out.println("\n+ insert_cnt [" + i + "]\n"); } catch (Exception e) { response_type = "FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if (pstmt != null) { try { pstmt.close(); } catch (Exception ex) { response_type = "FALSE"; } } System.out.println(" "); System.out.println("interface_seq:" + interface_seq); // .... cStmt = conn.prepareCall("{ call CREAT_NJOYNY_HMALL_ORDER(?,?,?) }"); cStmt.setLong(1, interface_seq); cStmt.registerOutParameter(2, Types.VARCHAR); cStmt.registerOutParameter(3, Types.VARCHAR); cStmt.executeUpdate(); String r_code = cStmt.getString(2); String r_msg = cStmt.getString(3); System.out.println("++++++++++++++++r_code : " + r_code); System.out.println("++++++++++++++++r_msg : " + r_msg); conn.commit(); System.out.println(" "); if (cStmt != null) { try { cStmt.close(); } catch (Exception e) { response_type = "FALSE"; } } conn.setAutoCommit(true); response_type = "TRUE"; } else { System.out.println(" "); } } else { System.out.println(" =.."); } cnt = 0; // .. } } } } } catch (Exception e) { System.out.println("run() : " + e.getMessage()); response_type = "FALSE"; } finally { } return response_type; }
From source file:NaverShopnGetOrder.java
/** * //from w ww. j av a 2 s . c o m * @param serviceName * @param operationName * @throws Exception */ public void encryptInit(String serviceName, String operationName) throws Exception { this.setServiceName(serviceName); this.setOperationName(operationName); Security.addProvider(new BouncyCastleProvider()); this.setTimestamp(SimpleCryptLib.getTimestamp()); this.setData(this.getTimestamp() + this.getServiceName() + this.getOperationName()); //generateSign this.setSignature(SimpleCryptLib.generateSign(this.getData(), this.getSecretKey())); //generateKey this.setEncryptKey(SimpleCryptLib.generateKey(this.getTimestamp(), this.getSecretKey())); //encrypt this.setEncryptedData(SimpleCryptLib.encrypt(this.getEncryptKey(), this.getPassword().getBytes("UTF-8"))); this.setDecryptedData( new String(SimpleCryptLib.decrypt(this.getEncryptKey(), this.getEncryptedData()), "UTF-8")); this.setHashedData(SimpleCryptLib.sha256(this.getPassword())); System.out.println("accessLicense : [" + this.getAccessLicense() + "]"); System.out.println("secretKey : [" + this.getSecretKey() + "]"); System.out.println("serviceName : [" + this.getServiceName() + "]"); System.out.println("operationName : [" + this.getOperationName() + "]"); System.out.println("timestamp : [" + this.getTimestamp() + "]"); System.out.println("signature : [" + this.getSignature() + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(this.getEncryptKey())) + "]"); System.out.println("encryptedData : [" + this.getEncryptedData() + "]"); System.out.println("decryptedData : [" + this.getDecryptedData() + "]"); System.out.println("sha256Data : [" + this.getHashedData() + "]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); }
From source file:NaverShopnSendShipping.java
public void encryptInit(String serviceName, String operationName) throws Exception { this.setServiceName(serviceName); this.setOperationName(operationName); Security.addProvider(new BouncyCastleProvider()); this.setTimestamp(SimpleCryptLib.getTimestamp()); this.setData(this.getTimestamp() + this.getServiceName() + this.getOperationName()); //generateSign this.setSignature(SimpleCryptLib.generateSign(this.getData(), this.getSecretKey())); //generateKey this.setEncryptKey(SimpleCryptLib.generateKey(this.getTimestamp(), this.getSecretKey())); //encrypt//from w w w. j a va 2 s . c o m this.setEncryptedData(SimpleCryptLib.encrypt(this.getEncryptKey(), this.getPassword().getBytes("UTF-8"))); this.setDecryptedData( new String(SimpleCryptLib.decrypt(this.getEncryptKey(), this.getEncryptedData()), "UTF-8")); this.setHashedData(SimpleCryptLib.sha256(this.getPassword())); System.out.println("accessLicense : [" + this.getAccessLicense() + "]"); System.out.println("secretKey : [" + this.getSecretKey() + "]"); System.out.println("serviceName : [" + this.getServiceName() + "]"); System.out.println("operationName : [" + this.getOperationName() + "]"); System.out.println("timestamp : [" + this.getTimestamp() + "]"); System.out.println("signature : [" + this.getSignature() + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(this.getEncryptKey())) + "]"); System.out.println("encryptedData : [" + this.getEncryptedData() + "]"); System.out.println("decryptedData : [" + this.getDecryptedData() + "]"); System.out.println("sha256Data : [" + this.getHashedData() + "]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==================encryptInit()===============================]"); System.out.println("[==============================================================]"); System.out.println("[==============================================================]"); }
From source file:NaverShopnImage.java
public String run() { String response_type = "FALSE"; try {// w w w .java 2s .c o m SimpleCryptLib SimpleCryptLib = new SimpleCryptLib(); Security.addProvider(new BouncyCastleProvider()); String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43"; String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA=="; String serviceName = "ImageService"; // String id = "eugink"; String password = "asdf0101"; String timestamp = null; String signature = null; String data = null; byte[] encryptKey = null; String encryptedData = null; String decryptedData = null; String hashedData = null; String operationName = "UploadImage"; //String orderID = "200087036"; //timestamp create timestamp = SimpleCryptLib.getTimestamp(); System.out.println("timestamp:" + timestamp); //generateSign data = timestamp + serviceName + operationName; signature = SimpleCryptLib.generateSign(data, secretKey); //generateKey encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey); //encrypt encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8")); //decrypt decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8"); //sha256 hashedData = SimpleCryptLib.sha256(password); NaverShopnImage NaverShopnImage = new NaverShopnImage(); System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getYesterday()); System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getToday()); System.out.println("accessLicense : [" + accessLicense + "]"); System.out.println("secretKey : [" + secretKey + "]"); System.out.println("serviceName : [" + serviceName + "]"); System.out.println("operationName : [" + operationName + "]"); System.out.println("timestamp : [" + timestamp + "]"); System.out.println("signature : [" + signature + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]"); System.out.println("encryptedData : [" + encryptedData + "]"); System.out.println("decryptedData : [" + decryptedData + "]"); System.out.println("sha256Data : [" + hashedData + "]"); /*String xmldata = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mall=\"http://mall.checkout.platform.nhncorp.com/\" xmlns:base=\"http://base.checkout.platform.nhncorp.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<mall:GetOrderInfoRequest>" + "<base:RequestID>?</base:RequestID>" + "<base:AccessCredentials>" + "<base:AccessLicense>"+ accessLicense +"</base:AccessLicense>" + "<base:Timestamp>"+ timestamp +"</base:Timestamp>" + "<base:Signature>"+ signature +"</base:Signature>" + "</base:AccessCredentials>" + "<base:DetailLevel>Full</base:DetailLevel>" + //<!-- value Full, Compact ) "<base:Version>2.0</base:Version>" + "<OrderID>"+ orderID +"</OrderID>" + "</mall:GetOrderInfoRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>";*/ System.out.println("NaverShopnImage.getYesterday():" + NaverShopnImage.getYesterday()); System.out.println("NaverShopnImage.getToday():" + NaverShopnImage.getToday()); String imglist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">" + "<soap:Header/>" + "<soap:Body>" + "<shop:UploadImageRequest>" + "<!--Optional:-->" + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>" + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>" + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>" + "</shop:AccessCredentials>" + "<shop:Version>2.0</shop:Version>" + "<SellerId>njoyny2</SellerId>" + "<ImageURLList>" + "<!--Zero or more repetitions:-->" + "<shop:URL>http://img.buynjoy.com/images_2011_1/b2c/thumb/12/X/X_van5502.jpg</shop:URL>" + "</ImageURLList>" + "</shop:UploadImageRequest>" + "</soap:Body>" + "</soap:Envelope>"; //Create socket String hostname = "sandbox.api.naver.com"; //String hostname = "api.naver.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/ShopN/ImageService"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0 \r\n"); wr.write("Host: sandbox.api.naver.com \r\n"); //wr.write("Host: api.naver.com \r\n"); //wr.write("Content-Length: " + xmldata.length() + "\r\n"); wr.write("Content-Length: " + imglist.length() + "\r\n"); wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n"); wr.write("SOAPAction: \"http://sandbox.api.naver.com/ShopN/ImageService\" \r\n"); //wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n"); wr.write("\r\n"); //Send data //wr.write(xmldata); wr.write(imglist); wr.flush(); // InputStream test = new InputStream(sock.getInputStream(),"UTF-8"); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")); String line = ""; String line_total = ""; String tmp = ""; String tmp2 = ""; String newxml = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("<?xml")) { line = line.replaceAll("
", " "); line_total = line_total + line; System.out.println(line); } } StringBuffer sf = new StringBuffer(); /* while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ sf.append(line+"\n"); // . } }*/ //char[] bufferResult = new char[1048576]; /* char[] bufferResult = new char[60000000]; int index = -1; while((index = rd.read(bufferResult)) != -1) { sf.append(bufferResult, 135, index); //response 133 135 }*/ //line_total = sf.toString().trim(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); line_total = line_total.replaceAll("n:", ""); //System.out.println(sf.toString().trim()); //xml2 InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8")); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); System.out.println("%%%%%%%%%%%%%%%%2222%%%%%%%%%%%%%%%%%"); Element element = document.getRootElement(); List envel_list = element.getChildren(); List body_list = null; List body_list1 = null; List result_list = null; List result_list1 = null; List result_list2 = null; List result_list3 = null; List result_list4 = null; List result_list5 = null; List info_list = null; List contr_group_list = null; List contr_info_list = null; PreparedStatement pstmt = null; ResultSet rs = null; CallableStatement cStmt = null; //conn.setAutoCommit(false); long UNIT_ID = 0; long cnt = 0; long interface_seq = 0; long DEL_QTY = 0; long ITEM_ID = 0; String ITEM_NAME = null; System.out.println("CategoryId.size:" + envel_list.size()); Element envel_el = (Element) envel_list.get(0); body_list = envel_el.getChildren(); //System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren()); //System.out.println("body_list.size:"+body_list.size()); Element body_el = (Element) body_list.get(0); result_list = body_el.getChildren("ImageList"); //System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren()); for (int h = 0; h < result_list.size(); h++) { Element body_el1 = (Element) result_list.get(h); result_list1 = body_el1.getChildren("Image"); //System.out.println("result_list1.size:"+result_list1.size()); //System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren()); for (int i = 0; i < result_list1.size(); i++) { Element body_el2 = (Element) result_list1.get(i); System.out.println("Source:" + body_el2.getChildText("Source")); System.out.println("URL:" + body_el2.getChildText("URL")); /* // StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into mirus_navershopnctg( \n"); setOrder.append(" CategoryName, Id, Name, Last, insert_date ,modify_date \n"); setOrder.append(" ) values ( \n"); setOrder.append(" ?, ?, ?, ?, sysdate,null \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); System.out.println("query:"+setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setString(1, body_el2.getChildText("CategoryName") ); // CategoryName pstmt.setLong( 2, Long.parseLong(body_el2.getChildText("Id"))); // Id pstmt.setString(3 , body_el2.getChildText("Name")); //Name pstmt.setString(4 , body_el2.getChildText("Last")); // Last pstmt.executeUpdate(); System.out.println("\n+ insert_cnt ["+i+"]\n"); } catch(Exception e) { response_type="FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}} */ /* Element body_el3 = (Element) result_list1.get(i); result_list3 = body_el3.getChildren("OrderProductList"); Element body_el4 = (Element) result_list1.get(i); result_list4 = body_el4.getChildren("Shipping"); */ /* for (int j = 0; j < result_list2.size(); j++) { Element body_el5 = (Element) result_list2.get(j);// Element body_el7 = (Element) result_list4.get(j);// Element body_el8 = (Element) result_list3.get(j); result_list5 = body_el8.getChildren("OrderProduct");// //result_list5 = (Element) result_list3.get(j);// System.out.println("$$55555$$"); if(body_el5.getChildText("OrderStatusCode").equals("OD0002")){// pstmt = conn.prepareStatement(selectChk.toString()); pstmt.setString(1, body_el5.getChildText("OrderID")); rs = pstmt.executeQuery(); if(rs.next()) { cnt = rs.getLong("cnt"); } System.out.println(" cnt:"+cnt); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} System.out.println("result_list5.size():"+result_list5.size()); for (int k = 0; k < result_list5.size(); k++) { Element body_el9 = (Element) result_list5.get(k); ITEM_NAME = body_el9.getChildText("ProductName"); DEL_QTY = Long.parseLong(body_el9.getChildText("Quantity")); pstmt = conn.prepareStatement(getInterfacedata); System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductID")); System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductOption")); pstmt.setLong(1, Long.parseLong(body_el9.getChildText("ProductID"))); pstmt.setString(2, body_el9.getChildText("ProductOption")); pstmt.setLong(3, Long.parseLong(body_el9.getChildText("ProductID"))); rs = pstmt.executeQuery(); if(rs.next()) { UNIT_ID = rs.getLong("UNIT_ID"); ITEM_ID = rs.getLong("ITEM_ID"); //DEL_QTY = rs.getLong("DEL_QTY"); } System.out.println("UNIT_ID:"+UNIT_ID); System.out.println("ITEM_ID:"+ITEM_ID); System.out.println("ITEM_NAME:"+ITEM_NAME); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} }// 1 . System.out.println("1111 333331"); String getInterfaceSeq = " select ktc_njoyny_hmall_if_seq.nextval interfaceSeq from dual "; pstmt = conn.prepareStatement(getInterfaceSeq); rs = pstmt.executeQuery(); if(rs.next()) { interface_seq = rs.getLong("interfaceSeq"); } System.out.println("+ interface_seq ["+interface_seq+"]"); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} if(cnt == 0) { // .. System.out.println("body_el5.getChildText:"+body_el5.getChildText("OrderID")); if(NaverShopnImage.run2(body_el5.getChildText("OrderID")).equals("SUCCESS")){// StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into ktc_njoyny_hmall_if( \n"); setOrder.append(" h_order_no, seq, order_date, recv_date, item_id, \n"); setOrder.append(" unit_id, item_name, price, qty, orderer_name, \n"); setOrder.append(" orderer_phone, orderer_cell_phone, orderer_eng_name, orderer_resi_no, orderer_email, \n"); setOrder.append(" msg_for_mall, del_plan_date, receiver_name, receiver_phone, receiver_cell_phone, \n"); setOrder.append(" receiver_zip_code, receiver_addr1, receiver_addr2, msg_for_outbnd, interface_date, \n"); setOrder.append(" interface_seq, sysregdt, coven_id \n"); setOrder.append(" ) values ( \n"); setOrder.append(" 'naver_'||?, ktc_njoyny_hmall_if_seq.nextval, to_date(?,'yyyy/mm/dd hh24:mi:ss'), sysdate, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, sysdate+5, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, sysdate, \n"); setOrder.append(" ?, sysdate, ? \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setLong(1, Long.parseLong(body_el5.getChildText("OrderID")) ); // h_order_no System.out.println(body_el5.getChildText("OrderID")); pstmt.setString(2 , body_el5.getChildText("OrderDateTime").substring(0,10)); //order_date System.out.println(body_el5.getChildText("OrderDateTime").substring(0,10)); pstmt.setLong(3 , ITEM_ID); // item_id System.out.println(ITEM_ID); pstmt.setLong(4 , UNIT_ID); // unit_id System.out.println(UNIT_ID); pstmt.setString(5 , ITEM_NAME); // ITEM_NAME System.out.println(ITEM_NAME); pstmt.setLong(6 , Long.parseLong(body_el5.getChildText("TotalProductAmount"))); //price -> 0.95 + + System.out.println(Long.parseLong(body_el5.getChildText("TotalProductAmount"))); pstmt.setLong(7 , DEL_QTY); //qty System.out.println(DEL_QTY); pstmt.setString(8 , new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); // orderer_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); pstmt.setString(9 , NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8"))); //orderer_phone System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererTel")), "UTF-8"))); pstmt.setString(10, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8"))); // orderer_cell_phone pstmt.setString(11, null); // orderer_eng_name pstmt.setString(12, null); // orderer_resi_no pstmt.setString(13, null); // orderer_email pstmt.setString(14, body_el7.getChildText("ShippingMessage")); // msg_for_mall pstmt.setString(15, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("Recipient")), "UTF-8")); // receiver_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("Recipient")), "UTF-8")); pstmt.setString(16, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_phone System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); pstmt.setString(17, NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_cell_phone System.out.println(NaverShopnImage.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); pstmt.setString(18, body_el7.getChildText("ZipCode")); //receiver_zip_code pstmt.setString(19, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress1")), "UTF-8")); //receiver_addr1 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress1")), "UTF-8")); pstmt.setString(20, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress2")), "UTF-8")); //receiver_addr2 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress2")), "UTF-8")); pstmt.setString(21, body_el7.getChildText("ShippingMessage")); // msg_for_outbnd System.out.println(body_el7.getChildText("ShippingMessage")); pstmt.setLong(22, interface_seq); // interface_seq pstmt.setString(23, "26050"); // coven_id pstmt.executeUpdate(); System.out.println("\n+ insert_cnt ["+i+"]\n"); } catch(Exception e) { response_type="FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}} System.out.println(" "); System.out.println("interface_seq:"+interface_seq); // .... cStmt = conn.prepareCall("{ call CREAT_NJOYNY_HMALL_ORDER(?,?,?) }"); cStmt.setLong(1, interface_seq); cStmt.registerOutParameter(2, Types.VARCHAR); cStmt.registerOutParameter(3, Types.VARCHAR); cStmt.executeUpdate(); String r_code = cStmt.getString(2); String r_msg = cStmt.getString(3); System.out.println("++++++++++++++++r_code : " + r_code); System.out.println("++++++++++++++++r_msg : " + r_msg); conn.commit(); System.out.println(" "); if(cStmt != null){ try{ cStmt.close(); } catch(Exception e){ response_type="FALSE";}} conn.setAutoCommit(true); response_type="TRUE"; }else{ System.out.println(" " ); } }else{ System.out.println(" =.." ); } cnt = 0; // .. } } */ } } } catch (Exception e) { System.out.println("run() : " + e.getMessage()); response_type = "FALSE"; } finally { } return response_type; }
From source file:JDES.java
public static void main(String[] argv) { try {//from www . j av a2 s .c o m // This generate a DES key based on your key String key = hexToASCII(argv[3]); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DES"); DESKeySpec mydeskeyspec = new DESKeySpec(key.getBytes()); SecretKey myDesKey = keyfactory.generateSecret(mydeskeyspec); // This automatically generate a DES key //KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); //SecretKey myDesKey = keygenerator.generateKey(); System.out.println("My Key: " + key); System.out.println("DES Key: " + new String(Hex.encode(myDesKey.getEncoded()))); Cipher desCipher; // Create the cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); // Initialize the cipher for encryption desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); //sensitive information byte[] iv = hexToASCII(argv[1]).getBytes(); String fileLocation = argv[5]; File file = new File(fileLocation); Scanner scnr = new Scanner(file); String line = scnr.nextLine(); boolean notDone = true; //start of loop while (notDone) { byte[] text = new byte[key.length()]; for (int i = 0; i < key.length(); i++) text[i] = (byte) line.charAt(i); System.out.println( "Text [Hex Format] : " + new String(Hex.encode(text)) + " length = " + text.length); System.out.println("Text : " + new String(text)); for (int i = 0; i < text.length; i++) { text[i] = (byte) (text[i] ^ iv[i]); } // Encrypt the text byte[] textEncrypted = desCipher.doFinal(text); System.out.println("Text Encryted : " + new String(Hex.encode(textEncrypted))); // Initialize the same cipher for decryption desCipher.init(Cipher.DECRYPT_MODE, myDesKey); // Decrypt the text byte[] textDecrypted = desCipher.doFinal(textEncrypted); for (int i = 0; i < textDecrypted.length; i++) { textDecrypted[i] = (byte) (textDecrypted[i] ^ iv[i]); } System.out.println("Text Decryted : " + new String(textDecrypted)); iv = text; notDone = false; } //End of Loop } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:NaverShopnGetCtg.java
public String run() { String response_type = "FALSE"; try {// w w w .j av a 2 s .com SimpleCryptLib SimpleCryptLib = new SimpleCryptLib(); Security.addProvider(new BouncyCastleProvider()); String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43"; String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA=="; String serviceName = "ProductService"; // String id = "eugink"; String password = "asdf0101"; String timestamp = null; String signature = null; String data = null; byte[] encryptKey = null; String encryptedData = null; String decryptedData = null; String hashedData = null; String operationName = "GetAllCategoryList"; //String orderID = "200087036"; //timestamp create timestamp = SimpleCryptLib.getTimestamp(); System.out.println("timestamp:" + timestamp); //generateSign data = timestamp + serviceName + operationName; signature = SimpleCryptLib.generateSign(data, secretKey); //generateKey encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey); //encrypt encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8")); //decrypt decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8"); //sha256 hashedData = SimpleCryptLib.sha256(password); NaverShopnGetCtg NaverShopnGetCtg = new NaverShopnGetCtg(); System.out.println("NaverShopnGetCtg.getYesterday():" + NaverShopnGetCtg.getYesterday()); System.out.println("NaverShopnGetCtg.getYesterday():" + NaverShopnGetCtg.getToday()); System.out.println("accessLicense : [" + accessLicense + "]"); System.out.println("secretKey : [" + secretKey + "]"); System.out.println("serviceName : [" + serviceName + "]"); System.out.println("operationName : [" + operationName + "]"); System.out.println("timestamp : [" + timestamp + "]"); System.out.println("signature : [" + signature + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]"); System.out.println("encryptedData : [" + encryptedData + "]"); System.out.println("decryptedData : [" + decryptedData + "]"); System.out.println("sha256Data : [" + hashedData + "]"); /*String xmldata = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mall=\"http://mall.checkout.platform.nhncorp.com/\" xmlns:base=\"http://base.checkout.platform.nhncorp.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<mall:GetOrderInfoRequest>" + "<base:RequestID>?</base:RequestID>" + "<base:AccessCredentials>" + "<base:AccessLicense>"+ accessLicense +"</base:AccessLicense>" + "<base:Timestamp>"+ timestamp +"</base:Timestamp>" + "<base:Signature>"+ signature +"</base:Signature>" + "</base:AccessCredentials>" + "<base:DetailLevel>Full</base:DetailLevel>" + //<!-- value Full, Compact ) "<base:Version>2.0</base:Version>" + "<OrderID>"+ orderID +"</OrderID>" + "</mall:GetOrderInfoRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>";*/ System.out.println("NaverShopnGetCtg.getYesterday():" + NaverShopnGetCtg.getYesterday()); System.out.println("NaverShopnGetCtg.getToday():" + NaverShopnGetCtg.getToday()); String ctglist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">" + "<soap:Header/>" + "<soap:Body>" + "<shop:GetAllCategoryListRequest>" + "<!--Optional:-->" + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>" + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>" + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>" + "</shop:AccessCredentials>" + "<shop:Version>1.0</shop:Version>" + "<!--Optional:-->" + "<Last>N</Last>" + //"<CategoryId></CategoryId>" + "</shop:GetAllCategoryListRequest>" + "</soap:Body>" + "</soap:Envelope>"; //Create socket String hostname = "sandbox.api.naver.com"; //String hostname = "api.naver.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/ShopN/ProductService"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0 \r\n"); wr.write("Host: sandbox.api.naver.com \r\n"); //wr.write("Host: api.naver.com \r\n"); //wr.write("Content-Length: " + xmldata.length() + "\r\n"); wr.write("Content-Length: " + ctglist.length() + "\r\n"); wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n"); wr.write("SOAPAction: \"http://sandbox.api.naver.com/ShopN/ProductService\" \r\n"); //wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n"); wr.write("\r\n"); //Send data //wr.write(xmldata); wr.write(ctglist); wr.flush(); // InputStream test = new InputStream(sock.getInputStream(),"UTF-8"); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")); String line = ""; String line_total = ""; String tmp = ""; String tmp2 = ""; String newxml = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("<?xml")) { line = line.replaceAll("
", " "); line_total = line_total + line; System.out.println(line); } } StringBuffer sf = new StringBuffer(); /* while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ sf.append(line+"\n"); // . } }*/ //char[] bufferResult = new char[1048576]; /* char[] bufferResult = new char[60000000]; int index = -1; while((index = rd.read(bufferResult)) != -1) { sf.append(bufferResult, 135, index); //response 133 135 }*/ //line_total = sf.toString().trim(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); line_total = line_total.replaceAll("n:", ""); //System.out.println(sf.toString().trim()); //xml2 InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8")); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); System.out.println("%%%%%%%%%%%%%%%%2222%%%%%%%%%%%%%%%%%"); Element element = document.getRootElement(); List envel_list = element.getChildren(); List body_list = null; List body_list1 = null; List result_list = null; List result_list1 = null; List result_list2 = null; List result_list3 = null; List result_list4 = null; List result_list5 = null; List info_list = null; List contr_group_list = null; List contr_info_list = null; PreparedStatement pstmt = null; ResultSet rs = null; CallableStatement cStmt = null; //conn.setAutoCommit(false); long UNIT_ID = 0; long cnt = 0; long interface_seq = 0; long DEL_QTY = 0; long ITEM_ID = 0; String ITEM_NAME = null; System.out.println("CategoryId.size:" + envel_list.size()); Element envel_el = (Element) envel_list.get(0); body_list = envel_el.getChildren(); //System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren()); //System.out.println("body_list.size:"+body_list.size()); Element body_el = (Element) body_list.get(0); result_list = body_el.getChildren("CategoryList"); //System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren()); for (int h = 0; h < result_list.size(); h++) { Element body_el1 = (Element) result_list.get(h); result_list1 = body_el1.getChildren("Category"); //System.out.println("result_list1.size:"+result_list1.size()); //System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren()); for (int i = 0; i < result_list1.size(); i++) { Element body_el2 = (Element) result_list1.get(i); System.out.println("CategoryName:" + body_el2.getChildText("CategoryName")); System.out.println("Id:" + body_el2.getChildText("Id")); System.out.println("Name:" + body_el2.getChildText("Name")); System.out.println("Last:" + body_el2.getChildText("Last")); // StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into mirus_navershopnctg( \n"); setOrder.append(" CategoryName, Id, Name, Last, insert_date ,modify_date \n"); setOrder.append(" ) values ( \n"); setOrder.append(" ?, ?, ?, ?, sysdate,null \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); System.out.println("query:" + setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setString(1, body_el2.getChildText("CategoryName")); // CategoryName pstmt.setLong(2, Long.parseLong(body_el2.getChildText("Id"))); // Id pstmt.setString(3, body_el2.getChildText("Name")); //Name pstmt.setString(4, body_el2.getChildText("Last")); // Last pstmt.executeUpdate(); System.out.println("\n+ insert_cnt [" + i + "]\n"); } catch (Exception e) { response_type = "FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if (pstmt != null) { try { pstmt.close(); } catch (Exception ex) { response_type = "FALSE"; } } /* Element body_el3 = (Element) result_list1.get(i); result_list3 = body_el3.getChildren("OrderProductList"); Element body_el4 = (Element) result_list1.get(i); result_list4 = body_el4.getChildren("Shipping"); */ /* for (int j = 0; j < result_list2.size(); j++) { Element body_el5 = (Element) result_list2.get(j);// Element body_el7 = (Element) result_list4.get(j);// Element body_el8 = (Element) result_list3.get(j); result_list5 = body_el8.getChildren("OrderProduct");// //result_list5 = (Element) result_list3.get(j);// System.out.println("$$55555$$"); if(body_el5.getChildText("OrderStatusCode").equals("OD0002")){// pstmt = conn.prepareStatement(selectChk.toString()); pstmt.setString(1, body_el5.getChildText("OrderID")); rs = pstmt.executeQuery(); if(rs.next()) { cnt = rs.getLong("cnt"); } System.out.println(" cnt:"+cnt); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} System.out.println("result_list5.size():"+result_list5.size()); for (int k = 0; k < result_list5.size(); k++) { Element body_el9 = (Element) result_list5.get(k); ITEM_NAME = body_el9.getChildText("ProductName"); DEL_QTY = Long.parseLong(body_el9.getChildText("Quantity")); pstmt = conn.prepareStatement(getInterfacedata); System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductID")); System.out.println("body_el9.getChildText:"+body_el9.getChildText("ProductOption")); pstmt.setLong(1, Long.parseLong(body_el9.getChildText("ProductID"))); pstmt.setString(2, body_el9.getChildText("ProductOption")); pstmt.setLong(3, Long.parseLong(body_el9.getChildText("ProductID"))); rs = pstmt.executeQuery(); if(rs.next()) { UNIT_ID = rs.getLong("UNIT_ID"); ITEM_ID = rs.getLong("ITEM_ID"); //DEL_QTY = rs.getLong("DEL_QTY"); } System.out.println("UNIT_ID:"+UNIT_ID); System.out.println("ITEM_ID:"+ITEM_ID); System.out.println("ITEM_NAME:"+ITEM_NAME); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} }// 1 . System.out.println("1111 333331"); String getInterfaceSeq = " select ktc_njoyny_hmall_if_seq.nextval interfaceSeq from dual "; pstmt = conn.prepareStatement(getInterfaceSeq); rs = pstmt.executeQuery(); if(rs.next()) { interface_seq = rs.getLong("interfaceSeq"); } System.out.println("+ interface_seq ["+interface_seq+"]"); if(rs!=null) {try{rs.close();} catch(Exception e){ response_type="FALSE";}} if(pstmt!=null) {try{pstmt.close();} catch(Exception e){ response_type="FALSE";}} if(cnt == 0) { // .. System.out.println("body_el5.getChildText:"+body_el5.getChildText("OrderID")); if(NaverShopnGetCtg.run2(body_el5.getChildText("OrderID")).equals("SUCCESS")){// StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into ktc_njoyny_hmall_if( \n"); setOrder.append(" h_order_no, seq, order_date, recv_date, item_id, \n"); setOrder.append(" unit_id, item_name, price, qty, orderer_name, \n"); setOrder.append(" orderer_phone, orderer_cell_phone, orderer_eng_name, orderer_resi_no, orderer_email, \n"); setOrder.append(" msg_for_mall, del_plan_date, receiver_name, receiver_phone, receiver_cell_phone, \n"); setOrder.append(" receiver_zip_code, receiver_addr1, receiver_addr2, msg_for_outbnd, interface_date, \n"); setOrder.append(" interface_seq, sysregdt, coven_id \n"); setOrder.append(" ) values ( \n"); setOrder.append(" 'naver_'||?, ktc_njoyny_hmall_if_seq.nextval, to_date(?,'yyyy/mm/dd hh24:mi:ss'), sysdate, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, ?, \n"); setOrder.append(" ?, sysdate+5, ?, ?, ?, \n"); setOrder.append(" ?, ?, ?, ?, sysdate, \n"); setOrder.append(" ?, sysdate, ? \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setLong(1, Long.parseLong(body_el5.getChildText("OrderID")) ); // h_order_no System.out.println(body_el5.getChildText("OrderID")); pstmt.setString(2 , body_el5.getChildText("OrderDateTime").substring(0,10)); //order_date System.out.println(body_el5.getChildText("OrderDateTime").substring(0,10)); pstmt.setLong(3 , ITEM_ID); // item_id System.out.println(ITEM_ID); pstmt.setLong(4 , UNIT_ID); // unit_id System.out.println(UNIT_ID); pstmt.setString(5 , ITEM_NAME); // ITEM_NAME System.out.println(ITEM_NAME); pstmt.setLong(6 , Long.parseLong(body_el5.getChildText("TotalProductAmount"))); //price -> 0.95 + + System.out.println(Long.parseLong(body_el5.getChildText("TotalProductAmount"))); pstmt.setLong(7 , DEL_QTY); //qty System.out.println(DEL_QTY); pstmt.setString(8 , new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); // orderer_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererName")), "UTF-8")); pstmt.setString(9 , NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8"))); //orderer_phone System.out.println(NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el5.getChildText("OrdererTel")), "UTF-8"))); pstmt.setString(10, NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el5.getChildText("OrdererTel")), "UTF-8"))); // orderer_cell_phone pstmt.setString(11, null); // orderer_eng_name pstmt.setString(12, null); // orderer_resi_no pstmt.setString(13, null); // orderer_email pstmt.setString(14, body_el7.getChildText("ShippingMessage")); // msg_for_mall pstmt.setString(15, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("Recipient")), "UTF-8")); // receiver_name System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("Recipient")), "UTF-8")); pstmt.setString(16, NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_phone System.out.println(NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); pstmt.setString(17, NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("RecipientTel1")), "UTF-8"))); // receiver_cell_phone System.out.println(NaverShopnGetCtg.getTel(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("RecipientTel1")), "UTF-8"))); pstmt.setString(18, body_el7.getChildText("ZipCode")); //receiver_zip_code pstmt.setString(19, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress1")), "UTF-8")); //receiver_addr1 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress1")), "UTF-8")); pstmt.setString(20, new String(SimpleCryptLib.decrypt(encryptKey,body_el7.getChildText("ShippingAddress2")), "UTF-8")); //receiver_addr2 System.out.println(new String(SimpleCryptLib.decrypt(encryptKey, body_el7.getChildText("ShippingAddress2")), "UTF-8")); pstmt.setString(21, body_el7.getChildText("ShippingMessage")); // msg_for_outbnd System.out.println(body_el7.getChildText("ShippingMessage")); pstmt.setLong(22, interface_seq); // interface_seq pstmt.setString(23, "26050"); // coven_id pstmt.executeUpdate(); System.out.println("\n+ insert_cnt ["+i+"]\n"); } catch(Exception e) { response_type="FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}} System.out.println(" "); System.out.println("interface_seq:"+interface_seq); // .... cStmt = conn.prepareCall("{ call CREAT_NJOYNY_HMALL_ORDER(?,?,?) }"); cStmt.setLong(1, interface_seq); cStmt.registerOutParameter(2, Types.VARCHAR); cStmt.registerOutParameter(3, Types.VARCHAR); cStmt.executeUpdate(); String r_code = cStmt.getString(2); String r_msg = cStmt.getString(3); System.out.println("++++++++++++++++r_code : " + r_code); System.out.println("++++++++++++++++r_msg : " + r_msg); conn.commit(); System.out.println(" "); if(cStmt != null){ try{ cStmt.close(); } catch(Exception e){ response_type="FALSE";}} conn.setAutoCommit(true); response_type="TRUE"; }else{ System.out.println(" " ); } }else{ System.out.println(" =.." ); } cnt = 0; // .. } } */ } } } catch (Exception e) { System.out.println("run() : " + e.getMessage()); response_type = "FALSE"; } finally { } return response_type; }
From source file:NaverShopnGetModel.java
public String run() { String response_type = "FALSE"; try {/* w w w . ja va 2 s . c om*/ SimpleCryptLib SimpleCryptLib = new SimpleCryptLib(); Security.addProvider(new BouncyCastleProvider()); String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43"; String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA=="; String serviceName = "ProductService"; // String id = "eugink"; String password = "asdf0101"; String timestamp = null; String signature = null; String data = null; byte[] encryptKey = null; String encryptedData = null; String decryptedData = null; String hashedData = null; String operationName = "GetModelList"; //String orderID = "200087036"; //timestamp create timestamp = SimpleCryptLib.getTimestamp(); System.out.println("timestamp:" + timestamp); //generateSign data = timestamp + serviceName + operationName; signature = SimpleCryptLib.generateSign(data, secretKey); //generateKey encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey); //encrypt encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8")); //decrypt decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8"); //sha256 hashedData = SimpleCryptLib.sha256(password); NaverShopnGetModel NaverShopnGetModel = new NaverShopnGetModel(); System.out.println("NaverShopnGetModel.getYesterday():" + NaverShopnGetModel.getYesterday()); System.out.println("NaverShopnGetModel.getYesterday():" + NaverShopnGetModel.getToday()); System.out.println("accessLicense : [" + accessLicense + "]"); System.out.println("secretKey : [" + secretKey + "]"); System.out.println("serviceName : [" + serviceName + "]"); System.out.println("operationName : [" + operationName + "]"); System.out.println("timestamp : [" + timestamp + "]"); System.out.println("signature : [" + signature + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]"); System.out.println("encryptedData : [" + encryptedData + "]"); System.out.println("decryptedData : [" + decryptedData + "]"); System.out.println("sha256Data : [" + hashedData + "]"); System.out.println("NaverShopnGetModel.getYesterday():" + NaverShopnGetModel.getYesterday()); System.out.println("NaverShopnGetModel.getToday():" + NaverShopnGetModel.getToday()); String modellist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">" + "<soap:Header/>" + "<soap:Body>" + "<shop:GetModelListRequest>" + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>" + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>" + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>" + "</shop:AccessCredentials>" + "<shop:Version>1.0</shop:Version>" + "<ModelName></ModelName>" + "</shop:GetModelListRequest>" + "</soap:Body>" + "</soap:Envelope>"; System.out.println("#######################################################"); System.out.println(modellist); System.out.println("#######################################################"); //Create socket String hostname = "sandbox.api.naver.com"; //String hostname = "api.naver.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/ShopN/ProductService"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0 \r\n"); wr.write("Host: sandbox.api.naver.com \r\n"); //wr.write("Host: api.naver.com \r\n"); //wr.write("Content-Length: " + xmldata.length() + "\r\n"); wr.write("Content-Length: " + modellist.length() + "\r\n"); wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n"); wr.write("SOAPAction: \"http://sandbox.api.naver.com/ShopN/ProductService\" \r\n"); //wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n"); wr.write("\r\n"); //Send data //wr.write(xmldata); wr.write(modellist); wr.flush(); // InputStream test = new InputStream(sock.getInputStream(),"UTF-8"); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")); String line = ""; String line_total = ""; String tmp = ""; String tmp2 = ""; String newxml = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("<?xml")) { line = line.replaceAll("
", " "); line_total = line_total + line; System.out.println(line); } } StringBuffer sf = new StringBuffer(); /* while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ sf.append(line+"\n"); // . } }*/ //char[] bufferResult = new char[1048576]; /* char[] bufferResult = new char[60000000]; int index = -1; while((index = rd.read(bufferResult)) != -1) { sf.append(bufferResult, 135, index); //response 133 135 }*/ //line_total = sf.toString().trim(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); line_total = line_total.replaceAll("n:", ""); //System.out.println(sf.toString().trim()); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%" + line_total + "%%%%%%%%%%%%%%%%%%%%%%%%%%"); //xml2 InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8")); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); System.out.println("%%%%%%%%%%%%%%%%2222%%%%%%%%%%%%%%%%%"); Element element = document.getRootElement(); List envel_list = element.getChildren(); List body_list = null; List body_list1 = null; List result_list = null; List result_list1 = null; List result_list2 = null; List result_list3 = null; List result_list4 = null; List result_list5 = null; List info_list = null; List contr_group_list = null; List contr_info_list = null; PreparedStatement pstmt = null; ResultSet rs = null; CallableStatement cStmt = null; //conn.setAutoCommit(false); long UNIT_ID = 0; long cnt = 0; long interface_seq = 0; long DEL_QTY = 0; long ITEM_ID = 0; String ITEM_NAME = null; System.out.println("GetModeListResponse.size:" + envel_list.size()); Element envel_el = (Element) envel_list.get(0); body_list = envel_el.getChildren(); //System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren()); //System.out.println("body_list.size:"+body_list.size()); Element body_el = (Element) body_list.get(0); result_list = body_el.getChildren(); System.out.println(body_list); System.out.println("###################################"); System.out.println(result_list); System.out.println("###################################"); Element body_el1 = (Element) result_list.get(5); result_list1 = body_el1.getChildren(); System.out.println(body_el1); System.out.println("###################################"); System.out.println(result_list1); System.out.println("###################################"); Element body_el2 = (Element) result_list1.get(0); result_list2 = body_el2.getChildren(); System.out.println(body_el2); System.out.println("###################################"); System.out.println(result_list2); System.out.println("###################################"); System.out.println("Code:" + body_el2.getChildText("Code")); // //System.out.println("body_list.size:"+body_list.size()); //System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren()); /*for (int h = 0; h < result_list.size(); h++) { Element body_el1 = (Element) result_list.get(h); result_list1 = body_el1.getChildren("Category"); //System.out.println("result_list1.size:"+result_list1.size()); //System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren()); for (int i = 0; i < result_list1.size(); i++) { Element body_el2 = (Element) result_list1.get(i); System.out.println("CategoryName:"+body_el2.getChildText("CategoryName")); System.out.println("Id:"+body_el2.getChildText("Id")); System.out.println("Name:"+body_el2.getChildText("Name")); System.out.println("Last:"+body_el2.getChildText("Last")); // StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into mirus_navershopnctg( \n"); setOrder.append(" CategoryName, Id, Name, Last, insert_date ,modify_date \n"); setOrder.append(" ) values ( \n"); setOrder.append(" ?, ?, ?, ?, sysdate,null \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); System.out.println("query:"+setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setString(1, body_el2.getChildText("CategoryName") ); // CategoryName pstmt.setLong( 2, Long.parseLong(body_el2.getChildText("Id"))); // Id pstmt.setString(3 , body_el2.getChildText("Name")); //Name pstmt.setString(4 , body_el2.getChildText("Last")); // Last pstmt.executeUpdate(); System.out.println("\n+ insert_cnt ["+i+"]\n"); } catch(Exception e) { response_type="FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}} } } */ } catch (Exception e) { System.out.println("run() : " + e.getMessage()); response_type = "FALSE"; } finally { } return response_type; }
From source file:NaverShopnGetArea.java
public String run() { String response_type = "FALSE"; try {/*from www .j a v a 2 s . c om*/ SimpleCryptLib SimpleCryptLib = new SimpleCryptLib(); Security.addProvider(new BouncyCastleProvider()); String accessLicense = "0100010000f3814c41974dc3e7f98d1cd213fa8b84c396872ff6c1abb57f0d2516f31cfb43"; String secretKey = "AQABAADKObge3IgWtlgfbo1TaLqHKpjfyGNKYuZbfOZB8m+WJA=="; String serviceName = "ProductService"; // String id = "eugink"; String password = "asdf0101"; String timestamp = null; String signature = null; String data = null; byte[] encryptKey = null; String encryptedData = null; String decryptedData = null; String hashedData = null; String operationName = "GetOriginAreaList"; //String orderID = "200087036"; //timestamp create timestamp = SimpleCryptLib.getTimestamp(); System.out.println("timestamp:" + timestamp); //generateSign data = timestamp + serviceName + operationName; signature = SimpleCryptLib.generateSign(data, secretKey); //generateKey encryptKey = SimpleCryptLib.generateKey(timestamp, secretKey); //encrypt encryptedData = SimpleCryptLib.encrypt(encryptKey, password.getBytes("UTF-8")); //decrypt decryptedData = new String(SimpleCryptLib.decrypt(encryptKey, encryptedData), "UTF-8"); //sha256 hashedData = SimpleCryptLib.sha256(password); NaverShopnGetArea NaverShopnGetArea = new NaverShopnGetArea(); System.out.println("NaverShopnGetArea.getYesterday():" + NaverShopnGetArea.getYesterday()); System.out.println("NaverShopnGetArea.getYesterday():" + NaverShopnGetArea.getToday()); System.out.println("accessLicense : [" + accessLicense + "]"); System.out.println("secretKey : [" + secretKey + "]"); System.out.println("serviceName : [" + serviceName + "]"); System.out.println("operationName : [" + operationName + "]"); System.out.println("timestamp : [" + timestamp + "]"); System.out.println("signature : [" + signature + "]"); System.out.println("encryptKey : [" + new String(Hex.encode(encryptKey)) + "]"); System.out.println("encryptedData : [" + encryptedData + "]"); System.out.println("decryptedData : [" + decryptedData + "]"); System.out.println("sha256Data : [" + hashedData + "]"); System.out.println("NaverShopnGetArea.getYesterday():" + NaverShopnGetArea.getYesterday()); System.out.println("NaverShopnGetArea.getToday():" + NaverShopnGetArea.getToday()); String ctglist = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:shop=\"http://shopn.platform.nhncorp.com/\">" + "<soap:Header/>" + "<soap:Body>" + "<shop:GetOriginAreaListRequest>" + "<!--Optional:-->" + "<shop:RequestID>njoyny2</shop:RequestID>" + "<shop:AccessCredentials>" + "<shop:AccessLicense>" + accessLicense + "</shop:AccessLicense>" + "<shop:Timestamp>" + timestamp + "</shop:Timestamp>" + "<shop:Signature>" + signature + "</shop:Signature>" + "</shop:AccessCredentials>" + "<shop:Version>2.0</shop:Version>" + "<!--Optional:-->" + "<OriginAreaName> </OriginAreaName>" + //"<CategoryId></CategoryId>" + "</shop:GetOriginAreaListRequest>" + "</soap:Body>" + "</soap:Envelope>"; //Create socket String hostname = "sandbox.api.naver.com"; //String hostname = "api.naver.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/ShopN/ProductService"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0 \r\n"); wr.write("Host: sandbox.api.naver.com \r\n"); //wr.write("Host: api.naver.com \r\n"); //wr.write("Content-Length: " + xmldata.length() + "\r\n"); wr.write("Content-Length: " + ctglist.length() + "\r\n"); wr.write("Content-Type: text/xml; charset=\"UTF-8\"\r\n"); wr.write("SOAPAction: \"http://sandbox.api.naver.com/ShopN/ProductService\" \r\n"); //wr.write("SOAPAction: \"http://api.naver.com/Checkout/MallService2\" \r\n"); wr.write("\r\n"); //Send data //wr.write(xmldata); wr.write(ctglist); wr.flush(); // InputStream test = new InputStream(sock.getInputStream(),"UTF-8"); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream(), "UTF-8")); String line = ""; String line_total = ""; String tmp = ""; String tmp2 = ""; String newxml = ""; while ((line = rd.readLine()) != null) { if (line.startsWith("<?xml")) { line = line.replaceAll("
", " "); line_total = line_total + line; System.out.println(line); } } StringBuffer sf = new StringBuffer(); /* while((line = rd.readLine()) != null){ if (line.startsWith("<?xml")){ sf.append(line+"\n"); // . } }*/ //char[] bufferResult = new char[1048576]; /* char[] bufferResult = new char[60000000]; int index = -1; while((index = rd.read(bufferResult)) != -1) { sf.append(bufferResult, 135, index); //response 133 135 }*/ //line_total = sf.toString().trim(); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); line_total = line_total.replaceAll("n:", ""); //System.out.println(sf.toString().trim()); System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%" + line_total + "%%%%%%%%%%%%%%%%%%%%%%%%%%"); //xml2 InputStream in = new ByteArrayInputStream(line_total.getBytes("UTF-8")); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(in); System.out.println("%%%%%%%%%%%%%%%%2222%%%%%%%%%%%%%%%%%"); Element element = document.getRootElement(); List envel_list = element.getChildren(); List body_list = null; List body_list1 = null; List result_list = null; List result_list1 = null; List result_list2 = null; List result_list3 = null; List result_list4 = null; List result_list5 = null; List info_list = null; List contr_group_list = null; List contr_info_list = null; PreparedStatement pstmt = null; ResultSet rs = null; CallableStatement cStmt = null; //conn.setAutoCommit(false); long UNIT_ID = 0; long cnt = 0; long interface_seq = 0; long DEL_QTY = 0; long ITEM_ID = 0; String ITEM_NAME = null; System.out.println("GetOriginAreaListResponse.size:" + envel_list.size()); Element envel_el = (Element) envel_list.get(0); body_list = envel_el.getChildren(); //System.out.println("+++++++11+++++++++++el.getName() : " + envel_el.getChildren()); //System.out.println("body_list.size:"+body_list.size()); Element body_el = (Element) body_list.get(0); result_list = body_el.getChildren(); System.out.println(body_list); System.out.println("###################################"); System.out.println(result_list); System.out.println("###################################"); Element body_el1 = (Element) result_list.get(5); result_list1 = body_el1.getChildren(); System.out.println(body_el1); System.out.println("###################################"); System.out.println(result_list1); System.out.println("###################################"); Element body_el2 = (Element) result_list1.get(0); result_list2 = body_el2.getChildren(); System.out.println(body_el2); System.out.println("###################################"); System.out.println(result_list2); System.out.println("###################################"); System.out.println("Code:" + body_el2.getChildText("Code")); // //System.out.println("body_list.size:"+body_list.size()); //System.out.println("++++++++22++++++++++el.getName() : " + body_el.getChildren()); /*for (int h = 0; h < result_list.size(); h++) { Element body_el1 = (Element) result_list.get(h); result_list1 = body_el1.getChildren("Category"); //System.out.println("result_list1.size:"+result_list1.size()); //System.out.println("++++++++33++++++++++el.getName() : " + body_el1.getChildren()); for (int i = 0; i < result_list1.size(); i++) { Element body_el2 = (Element) result_list1.get(i); System.out.println("CategoryName:"+body_el2.getChildText("CategoryName")); System.out.println("Id:"+body_el2.getChildText("Id")); System.out.println("Name:"+body_el2.getChildText("Name")); System.out.println("Last:"+body_el2.getChildText("Last")); // StringBuffer setOrder = new StringBuffer(); setOrder.append(" insert \n"); setOrder.append(" into mirus_navershopnctg( \n"); setOrder.append(" CategoryName, Id, Name, Last, insert_date ,modify_date \n"); setOrder.append(" ) values ( \n"); setOrder.append(" ?, ?, ?, ?, sysdate,null \n"); setOrder.append(" ) \n"); pstmt = conn.prepareStatement(setOrder.toString()); System.out.println("query:"+setOrder.toString()); int insert_cnt = 0; try { pstmt.clearParameters(); // pstmt.setString(1, body_el2.getChildText("CategoryName") ); // CategoryName pstmt.setLong( 2, Long.parseLong(body_el2.getChildText("Id"))); // Id pstmt.setString(3 , body_el2.getChildText("Name")); //Name pstmt.setString(4 , body_el2.getChildText("Last")); // Last pstmt.executeUpdate(); System.out.println("\n+ insert_cnt ["+i+"]\n"); } catch(Exception e) { response_type="FALSE"; e.printStackTrace(); conn.rollback(); break; } conn.commit(); if(pstmt != null) {try{ pstmt.close(); } catch(Exception ex){ response_type="FALSE";}} } } */ } catch (Exception e) { System.out.println("run() : " + e.getMessage()); response_type = "FALSE"; } finally { } return response_type; }
From source file:ai.eve.volley.Request.java
License:Apache License
/** * Converts <code>params</code> into an application/x-www-form-urlencoded * encoded string./* w ww . j a v a 2s . c o m*/ */ public static byte[] encodeParameters(Map<String, String> params, String paramsEncoding) { try { if (params == null || params.size() <= 0) { return null; } Collection<String> keyset = params.keySet(); List<String> list = new ArrayList<String>(keyset); Collections.sort(list); StringBuilder encodedParams = new StringBuilder(); for (String key : list) { encodedParams.append(key); encodedParams.append('='); encodedParams.append(params.get(key)); encodedParams.append('&'); } MessageDigest digest = MD5.Digest.getInstance("MD5"); ELog.D(EApplication.rsaPublicKey + encodedParams.toString()); digest.update((EApplication.rsaPublicKey + encodedParams.toString()).getBytes()); byte[] result = digest.digest(); encodedParams.append("SIGN=" + new String(Hex.encode(result))); ELog.I("?", encodedParams.toString()); return encodedParams.toString().getBytes(paramsEncoding); } catch (Exception uee) { throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee); } }