|
@@ -1,5 +1,7 @@
|
|
|
package com.fdkankan.common.util;
|
|
|
|
|
|
+import net.lingala.zip4j.exception.ZipException;
|
|
|
+
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.SecretKey;
|
|
|
import javax.crypto.SecretKeyFactory;
|
|
@@ -10,6 +12,7 @@ import java.security.SecureRandom;
|
|
|
|
|
|
public class PasswordUtils {
|
|
|
|
|
|
+ public static char[] arr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
|
|
|
|
|
/**
|
|
|
* JAVA6支持以下任意一种算法 PBEWITHMD5ANDDES PBEWITHMD5ANDTRIPLEDES
|
|
@@ -166,25 +169,69 @@ public class PasswordUtils {
|
|
|
return (byte) "0123456789ABCDEF".indexOf(c);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws ZipException {
|
|
|
|
|
|
//管理后台密码加解密
|
|
|
- String userName = "admin6";
|
|
|
- String password = "123456";
|
|
|
+// String userName = "admin6";
|
|
|
+// String password = "123456";
|
|
|
+//
|
|
|
+// try {
|
|
|
+// byte[] salt = PasswordUtils.getStaticSalt();
|
|
|
+// String ciphertext = PasswordUtils.encrypt(userName, password, salt);
|
|
|
+// System.out.println(ciphertext);
|
|
|
+// String plaintext = PasswordUtils.decrypt(ciphertext, password, salt);
|
|
|
+// System.out.println(plaintext);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+// String filePath = "C:\\Users\\dsx\\Desktop\\90d95cdb5_202211141023024060\\90d95cdb5_202211141023024060.zip";
|
|
|
+// String zipFileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
|
|
|
+// System.out.println(zipFileName);
|
|
|
+// String finalFilePath = FileUtil.getParent(filePath, 1);
|
|
|
+// System.out.println(finalFilePath);
|
|
|
+//
|
|
|
+// String zipName = FileUtil.mainName(zipFileName);
|
|
|
+// System.out.println(zipName);
|
|
|
+
|
|
|
+// ZipFile zipFile = new ZipFile(new File(filePath));
|
|
|
+// if (zipFile.isEncrypted()) {
|
|
|
+// String pwd = zipFileName.substring(0, 5).concat(zipFileName.substring(0, 5));
|
|
|
+// zipFile.setPassword(pwd);
|
|
|
+// zipFile.extractAll(finalFilePath);
|
|
|
+// } else {
|
|
|
+// ZipUtil.unzip(filePath, finalFilePath);
|
|
|
+// }
|
|
|
|
|
|
- try {
|
|
|
- byte[] salt = PasswordUtils.getStaticSalt();
|
|
|
- String ciphertext = PasswordUtils.encrypt(userName, password, salt);
|
|
|
- System.out.println(ciphertext);
|
|
|
- String plaintext = PasswordUtils.decrypt(ciphertext, password, salt);
|
|
|
- System.out.println(plaintext);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模拟前端密码加密
|
|
|
+ * @param str
|
|
|
+ */
|
|
|
+ public static String decycptPasswordWeb(String str){
|
|
|
+ int num = 2;
|
|
|
+ String front = randomWord(8);
|
|
|
+ String middle = randomWord(8);
|
|
|
+ String end = randomWord(8);
|
|
|
|
|
|
+ String str1 = str.substring(0, num);
|
|
|
+ String str2 = str.substring(num);
|
|
|
|
|
|
+ return front + str2 + middle + str1 + end ;
|
|
|
+ }
|
|
|
|
|
|
+ public static String randomWord(Integer min) {
|
|
|
+ String str = "";
|
|
|
+ Integer range = min;
|
|
|
+ // 随机产生
|
|
|
+ for (int i = 0; i < range; i++) {
|
|
|
+ int pos = (int) Math.round(Math.random() * (arr.length - 1));
|
|
|
+ str += arr[pos];
|
|
|
+ }
|
|
|
+ return str;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|