MD5Util.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.hssx.pcbms.util;
  2. import org.springframework.util.DigestUtils;
  3. import java.io.*;
  4. import java.text.ParseException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.zip.ZipEntry;
  8. import java.util.zip.ZipOutputStream;
  9. /**
  10. * Author: 吴涛涛 cuiyi@itany.com
  11. * Date : 2019 - 07 - 25 16:56
  12. * Description:<描述>MD5加密工具
  13. * Version: 1.0
  14. */
  15. public class MD5Util {
  16. public static String getPassword(String password) {
  17. return DigestUtils.md5DigestAsHex(password.getBytes());
  18. }
  19. public static void main(String[] args) throws ParseException {
  20. }
  21. // public void zipDemo() {
  22. // //需要压缩的文件--包括文件地址和文件名
  23. // String[] path = {"D:\\666.jpg", "D:\\777.jpg"};
  24. // // 要生成的压缩文件地址和文件名称
  25. // String desPath = "D:\\new.zip";
  26. // File zipFile = new File(desPath);
  27. // ZipOutputStream zipStream = null;
  28. // FileInputStream zipSource = null;
  29. // BufferedInputStream bufferStream = null;
  30. // try {
  31. // //构造最终压缩包的输出流
  32. // zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
  33. // for (int i = 0; i < path.length; i++) {
  34. // File file = new File(path[i]);
  35. // //将需要压缩的文件格式化为输入流
  36. // zipSource = new FileInputStream(file);
  37. // //压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
  38. // ZipEntry zipEntry = new ZipEntry(i + "2222.jpg");//"2222.jpg"是添加到压缩包里的源文件的名字加i是防止名字相同出错
  39. // //定位该压缩条目位置,开始写入文件到压缩包中
  40. // zipStream.putNextEntry(zipEntry);
  41. // //输入缓冲流
  42. // bufferStream = new BufferedInputStream(zipSource, 1024 * 10);
  43. // int read = 0;
  44. // //创建读写缓冲区
  45. // byte[] buf = new byte[1024 * 10];
  46. // while ((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) {
  47. // zipStream.write(buf, 0, read);
  48. // }
  49. // }
  50. //
  51. // } catch (Exception e) {
  52. // e.printStackTrace();
  53. // } finally {
  54. // //关闭流
  55. // try {
  56. // if (null != bufferStream) bufferStream.close();
  57. // if (null != zipStream) zipStream.close();
  58. // if (null != zipSource) zipSource.close();
  59. // } catch (IOException e) {
  60. // e.printStackTrace();
  61. // }
  62. // }
  63. // }
  64. //
  65. // public static void zip4jDemo(){
  66. //// 生成的压缩文件
  67. // ZipFile zipFile = null;
  68. // try {
  69. // zipFile = new ZipFile("D:\\aa.zip");
  70. //
  71. // ZipParameters parameters = new ZipParameters();
  72. // // 压缩方式
  73. // parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
  74. // // 压缩级别
  75. // parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
  76. // // 要打包的文件夹
  77. // File currentFile = new File("D:\\666");
  78. // File[] fs = currentFile.listFiles();
  79. // // 遍历test文件夹下所有的文件、文件夹
  80. // for (File f : fs) {
  81. // if (f.isDirectory()) {
  82. // zipFile.addFolder(f.getPath(), parameters);
  83. // } else {
  84. // zipFile.addFile(f, parameters);
  85. // }
  86. // }
  87. // zipFile.addFolder("D:\\666", parameters);
  88. // } catch (Exception e) {
  89. // e.printStackTrace();
  90. // }
  91. // }
  92. }