|
|
@@ -1,11 +1,12 @@
|
|
|
package com.fs.his.utils;
|
|
|
|
|
|
import com.fs.common.utils.ParseUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.util.Base64;
|
|
|
-
|
|
|
+@Slf4j
|
|
|
public class PhoneUtil {
|
|
|
|
|
|
public static String encryptPhone(String text) {
|
|
|
@@ -38,6 +39,55 @@ public class PhoneUtil {
|
|
|
}
|
|
|
return text;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 智能解密手机号 - 可处理加密、掩码和明文三种格式
|
|
|
+ * @param phoneText 可能是加密、掩码或明文的电话号码
|
|
|
+ * @return 解密后的手机号或原文
|
|
|
+ */
|
|
|
+ public static String decryptPhoneNew(String phoneText) {
|
|
|
+ // 参数校验
|
|
|
+ if (phoneText == null || phoneText.isEmpty()) {
|
|
|
+ return phoneText;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否是明文电话号码格式 (纯数字)
|
|
|
+ if (phoneText.matches("^\\d+$")) {
|
|
|
+ return phoneText; // 已经是明文,直接返回
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否是掩码电话号码格式 (包含*)
|
|
|
+ if (phoneText.contains("*")) {
|
|
|
+ return phoneText; // 掩码格式,直接返回
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试作为加密电话号码解密
|
|
|
+ try {
|
|
|
+
|
|
|
+ SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, secretKey);
|
|
|
+
|
|
|
+ byte[] decodedBytes = Base64.getDecoder().decode(phoneText);
|
|
|
+ byte[] decryptedBytes = cipher.doFinal(decodedBytes);
|
|
|
+ String decryptedPhone = new String(decryptedBytes);
|
|
|
+
|
|
|
+ // 验证解密结果是否为有效电话号码
|
|
|
+ if (decryptedPhone.matches("^\\d{5,20}$")) { // 简单验证是5-20位数字
|
|
|
+ return decryptedPhone;
|
|
|
+ } else {
|
|
|
+ // 解密结果不像有效电话号码
|
|
|
+ System.out.println("解密结果不是有效电话号码: " + decryptedPhone);
|
|
|
+ return phoneText;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常,但不影响程序流程
|
|
|
+ log.error("Phone decryption failed for: {}",phoneText,e);
|
|
|
+ return phoneText; // 解密失败返回原文
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 解密加*
|
|
|
*/
|