聊天记录解密

其实这个功能的总思路是 包所有的QQ聊天记录和旺旺的聊天记录先拷贝到word,让word把图片进行base64的加密,切记word保存时候的格式是mht的

比如我保存了一份聊天记录,用notepad++打开


可以看到在<!--StartFragment-->
          <!--EndFragment-->标签内容才是你拷贝的内容图片后面的src是content-Location后面的字符


后面我们就是解析了

public String newAddServeRecord() {  
  1.         InputStreamReader r = null;  
  2.         BufferedReader br = null;  
  3.         try {  
  4.             String uploadPath = Tools.getStrutsProp().getValue("uploadPath")  
  5.                     + "recordImgs/";  
  6.             File recf = new File(uploadPath);  
  7.             recf.mkdirs();  
  8.             String urlPath = Tools.getStrutsProp().getValue("urlPath")  
  9.                     + "recordImgs/";  
  10.   
  11.             r = new InputStreamReader(new FileInputStream(mhtFile), "UTF-8");  
  12.             br = new BufferedReader(r);  
  13.               
  14.             String result = "";  
  15.             Map<String, String> imgMap = new HashMap<String, String>();  
  16.               
  17.             String startFragment = "<!--StartFragment-->";  
  18.             String endFragment = "<!--EndFragment-->";  
  19.             String base64 = "Content-Transfer-Encoding: base64";  
  20.             String location = "Content-Location: ";  
  21.   
  22.             String str = null;  
  23.             while ((str = br.readLine()) != null) {  
  24.                 if (str.indexOf(startFragment) != -1) {  
  25.   
  26.                     if (str.indexOf(endFragment) != -1) {  
  27.                         result += str.substring(str.indexOf(startFragment)  
  28.                                 + startFragment.length(),  
  29.                                 str.indexOf(endFragment));  
  30.                     } else {  
  31.                         result += str.substring(str.indexOf(startFragment)  
  32.                                 + startFragment.length(), str.length());  
  33.                     }  
  34.                 }  
  35.   
  36.                 if (str.indexOf(endFragment) != -1) {  
  37.                     result += str.substring(0, str.indexOf(endFragment));  
  38.                 }  
  39.   
  40.                 if (str.indexOf(base64) != -1) {  
  41.                     String locationPath = br.readLine();  
  42.                     locationPath = locationPath.replace(location, "");  
  43.   
  44.                     br.readLine();  
  45.                     String base64Img = br.readLine();  
  46.                     imgMap.put(locationPath, base64Img);  
  47.                 }  
  48.   
  49.             }  
  50.   
  51.             result = result.replaceAll("=20"" ").replaceAll("=3D""=")  
  52.                     .replaceAll("<IMG""<img");  
  53.   
  54.             for (String key : imgMap.keySet()) {  
  55.                 byte[] imgByte = Base64.decode(imgMap.get(key));  
  56.   
  57.                 String fileName = Tools.getDateToSEC() + Tools.getThree()  
  58.                         + key.substring(key.lastIndexOf("."));  
  59.   
  60.                 FileOutputStream imgOut = new FileOutputStream(uploadPath  
  61.                         + fileName);  
  62.                 imgOut.write(imgByte);  
  63.                 imgOut.close();  
  64.                 result = result.replace(key, urlPath + fileName);  
  65.             }  
  66.               
  67.             // 写入数据库   
  68.             ServeRecord sr = new ServeRecord();  
  69.             sr.setDate(new Date());  
  70.             sr.setContent(result);  
  71.             sr.setServeCustomer(((Admin) getSession().get(Constant.ADMIN))  
  72.                     .getName());  
  73.             sr.setCustomerId(customer.getId() + "");  
  74.             serveRecordDao.insert(sr);  
  75.             state = "okrecord";  
  76.         } catch (Exception e) {  
  77.             logger.error("CustomerManagerAction.newAddServeRecord", e);  
  78.             return ERROR;  
  79.         } finally {  
  80.             try {  
  81.                 if (null != br) {  
  82.                     br.close();  
  83.                 }  
  84.                 if (null != r) {  
  85.                     r.close();  
  86.                 }  
  87.             } catch (IOException e) {  
  88.                 logger.error(  
  89.                         "CustomerManagerAction.newAddServeRecord[close] error!",  
  90.                         e);  
  91.                 return ERROR;  
  92.             }  
  93.         }  
  94.         return SUCCESS;  
  95.     }  

你可能感兴趣的:(聊天记录解密)