using System; using System.Collections.Generic; using System.Text; namespace CommonUtil.DMEncrypt { /// /// /// public static class Sensitive { /// /// 姓名脱敏 /// /// /// public static string NameSensitive(string name) { if (name.IsNullOrEmpty()) { return null; } string getName = name.Substring(0, 1); for (int i = 0; i < name.Length - 1; i++) { getName += "*"; } return getName; } /// /// 手机号脱敏 /// /// /// public static string MobileSensitive(string mobile) { if (mobile.IsNullOrEmpty()) { return null; } string contentFirst = mobile.Substring(0, 3); string contentSecond = mobile.Substring(7, 4); string getMobile = contentFirst + "****" + contentSecond; return getMobile; } /// /// 邮箱脱敏 /// /// /// public static string EmailSensitive(string email) { if (email.IsNullOrEmpty()) { return null; } string getEmail = ""; char[] vs = email.ToCharArray(); List lists = new List(); foreach (var value in vs) { lists.Add(value.ToString()); } string[] strs = lists.ToArray(); int firstIndex = email.IndexOf("@"); int secondIndex = email.IndexOf("."); for (int i = 2; i < firstIndex; i++) { strs[i] = "*"; } for (int j = firstIndex + 2; j < secondIndex; j++) { strs[j] = "*"; } foreach (var value in strs) { getEmail += value; } return getEmail; } /// /// 地址脱敏 /// /// 省 /// 市 /// 区 /// 地址 /// public static string AddressSensitive(string province, string city, string area, string address) { string getAddress = province + city + area; if (!address.IsNullOrEmpty()) { getAddress += "*****"; } return getAddress; } } }