|
@@ -14,6 +14,7 @@ import com.ruoyi.system.api.model.LoginUser;
|
|
|
import com.ruoyi.system.sm4.SM4Utils;
|
|
|
import com.ruoyi.system.utils.Encryption;
|
|
|
import com.ruoyi.system.utils.SubCodeUtil;
|
|
|
+import com.sun.javaws.Main;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -98,6 +99,74 @@ public class SecurityUtils
|
|
|
sm4.secretKey = key;
|
|
|
return sm4.decryptData_ECB(data);
|
|
|
}
|
|
|
+ public static String maskA(String str, int cd) {
|
|
|
+ int cdc = str.length() - 2 * cd;
|
|
|
+ if (cdc > 0) {
|
|
|
+ String reptext = "";
|
|
|
+ for (int k = 0; k < cdc; k++) {
|
|
|
+ reptext = reptext + "✱";
|
|
|
+ }
|
|
|
+ return str.substring(0, cd) + reptext + str.substring(str.length() - cd);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ public static String masks(String str,int type){
|
|
|
+ int strcd = str != null ? str.length() : 0;
|
|
|
+ if (strcd > 0) {
|
|
|
+ if (type == 1) //姓名
|
|
|
+ {
|
|
|
+ if (strcd > 1) {
|
|
|
+ int cdc = strcd - 1;
|
|
|
+ String reptext = "";
|
|
|
+ for (int k = 0; k < cdc; k++) {
|
|
|
+ reptext = reptext + "✱";
|
|
|
+ }
|
|
|
+ return reptext + str.substring(cdc);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (type == 2)//身份证号
|
|
|
+ {
|
|
|
+ if (strcd == 18) {
|
|
|
+ return str.substring(0, 3) + "✱✱✱✱✱" + str.substring(8, 9) + "✱✱✱✱✱✱✱" + str.substring(16, 17) + "✱";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return maskA(str, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (type == 3)//手机号
|
|
|
+ {
|
|
|
+ if (strcd == 11) {
|
|
|
+ return str.substring(0, 2) + "✱✱✱✱✱✱✱✱" + str.substring(10, 11);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return maskA(str, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (type == 4)//住址
|
|
|
+ {
|
|
|
+ return maskA(str, 2);
|
|
|
+ }
|
|
|
+ else if (type == 5)//邮件地址
|
|
|
+ {
|
|
|
+ return maskA(str, 2);
|
|
|
+ }
|
|
|
+ else if (type == 6)//邮件地址
|
|
|
+ {
|
|
|
+ return maskA(str, 1);
|
|
|
+ }
|
|
|
+ else //其他
|
|
|
+ {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ }
|
|
|
public static String sm4encrypt_CBC(String key,String iv,String data){
|
|
|
SM4Utils sm4 = new SM4Utils();
|
|
|
sm4.secretKey = key;
|
|
@@ -315,4 +384,12 @@ public class SecurityUtils
|
|
|
|| (isPureChar && hasSpecChar) || isNumAndChar && hasSpecChar) || isNumAndChar;
|
|
|
return isLegal;
|
|
|
}
|
|
|
+ public static void mainTest(String[] args)
|
|
|
+ {
|
|
|
+ System.out.println(masks("我开双方都三始",1));
|
|
|
+ System.out.println(masks("220122197601247014",2));
|
|
|
+ System.out.println(masks("13630594359",3));
|
|
|
+ System.out.println(masks("吉林省农安县",4));
|
|
|
+ System.out.println(masks("吉林省农安县",99));
|
|
|
+ }
|
|
|
}
|