java脱敏处理

package com.testjdbc.util;
import org.apache.commons.lang3.StringUtils;/*** 信息脱敏工具类**/
public class DataMaskingUtils {public static void main(String[] args) {//中文名脱敏String s1 = DataMaskingUtils.chineseName("欧阳娜娜"); //欧***System.out.println("中文名脱敏1:"+s1);String s2 = DataMaskingUtils.chineseName("欧阳", "娜娜");//欧阳**System.out.println("中文名脱敏2:"+s2);//字符脱敏String s3 = DataMaskingUtils.strMasking("信息脱敏工具类测试字符脱敏", 4, 2);String s4 = DataMaskingUtils.strMasking("字符脱敏", 5, 2);String s5 = DataMaskingUtils.strMasking("字符脱敏", 2, 3);String s6 = DataMaskingUtils.strMasking("字符脱敏", 3, 3);System.out.println("字符脱敏前4位, 后2位:"+s3);System.out.println("字符脱敏前5位, 后2位:"+s4);System.out.println("字符脱敏前2位, 后3位:"+s5);System.out.println("字符脱敏前3位, 后3位:"+s6);//[身份证号] 脱敏 后四位其他隐藏String s7 = DataMaskingUtils.idCardNum("430903199909093412");System.out.println("[身份证号] 脱敏 后四位其他隐藏:"+s7);//[身份证号]脱敏 前六位,后四位,其他用隐藏String s8 = DataMaskingUtils.idCard("430903199909093412");System.out.println("[身份证号]脱敏 前六位,后四位,其他用隐藏:"+s8);//[固定电话] 后四位,其他隐藏String s9 = DataMaskingUtils.fixedPhone("13077098909");System.out.println("[固定电话] 后四位,其他隐藏:"+s9);//[手机号码] 前三位,后四位,其他隐藏<例子:138******1234>String s10 = DataMaskingUtils.mobilePhone("13879081234");System.out.println("[手机号码] 前三位,后四位,其他隐藏:"+s10);//[地址] 只显示到地区,不显示详细地址String s11 = DataMaskingUtils.address("北京市丰台区莲花池东路118号", 10);System.out.println("[地址] 只显示到地区,不显示详细地址:"+s11);//[电子邮箱] 邮箱前缀仅显示第一个字母String s12 = DataMaskingUtils.email("zhangsan123@163.com");System.out.println("[电子邮箱] 邮箱前缀仅显示第一个字母:"+s12);//[银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号String s13 = DataMaskingUtils.bankCard("622260011111111111234");System.out.println("[银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号:"+s13);//[公司开户银行联号] 公司开户银行联行号,显示前两位,其他用星号隐藏,每位1个星号String s14 = DataMaskingUtils.cnapsCode("6222600111111111234");System.out.println("[公司开户银行联号] 公司开户银行联行号,显示前两位,其他用星号隐藏,每位1个星号:"+s14);}/*** 字符脱敏.** @param str the str* @param pre the pre 前几位* @param suf the suf 后几位* @return the string*/public static String strMasking(String str, int pre, int suf) {if (StringUtils.isBlank(str)) {return str;}if (pre <= 0 && suf <= 0) {return str;}int len = str.length();if (len > (pre + suf)) {return subPre(str, pre) +fill("", '*', len - pre - suf, false) +subSufByLength(str, suf);} else if (len > pre && pre > 0) {return subPre(str, pre) +fill("", '*', len - pre, false);} else if (len > suf && suf > 0) {return fill("", '*', len - suf, false) +subSufByLength(str, suf);} else {return fill("", '*', len, false);}}public static String subSufByLength(CharSequence string, int length) {if (isEmpty(string)) {return null;} else {return length <= 0 ? "" : sub(string, -length, string.length());}}public static String fill(String str, char filledChar, int len, boolean isPre) {int strLen = str.length();if (strLen > len) {return str;} else {String filledStr = repeat(filledChar, len - strLen);return isPre ? filledStr.concat(str) : str.concat(filledStr);}}public static String repeat(char c, int count) {if (count <= 0) {return "";} else {char[] result = new char[count];for(int i = 0; i < count; ++i) {result[i] = c;}return new String(result);}}public static String repeat(CharSequence str, int count) {if (null == str) {return null;} else if (count > 0 && str.length() != 0) {if (count == 1) {return str.toString();} else {int len = str.length();long longSize = (long) len * (long) count;int size = (int) longSize;if ((long) size != longSize) {throw new ArrayIndexOutOfBoundsException("Required String length is too large: " + longSize);} else {char[] array = new char[size];str.toString().getChars(0, len, array, 0);int n;for (n = len; n < size - n; n <<= 1) {System.arraycopy(array, 0, array, n, n);}System.arraycopy(array, 0, array, n, size - n);return new String(array);}}} else {return "";}}public static String hide(CharSequence str, int startInclude, int endExclude) {return replace(str, startInclude, endExclude, '*');}public static String replace(CharSequence str, int startInclude, int endExclude, char replacedChar) {if (isEmpty(str)) {return str(str);} else {String originalStr = str(str);int[] strCodePoints = originalStr.codePoints().toArray();int strLength = strCodePoints.length;if (startInclude > strLength) {return originalStr;} else {if (endExclude > strLength) {endExclude = strLength;}if (startInclude > endExclude) {return originalStr;} else {StringBuilder stringBuilder = new StringBuilder();for(int i = 0; i < strLength; ++i) {if (i >= startInclude && i < endExclude) {stringBuilder.append(replacedChar);} else {stringBuilder.append(new String(strCodePoints, i, 1));}}return stringBuilder.toString();}}}}public static String replace(CharSequence str, int startInclude, int endExclude, CharSequence replacedStr) {if (isEmpty(str)) {return str(str);} else {String originalStr = str(str);int[] strCodePoints = originalStr.codePoints().toArray();int strLength = strCodePoints.length;if (startInclude > strLength) {return originalStr;} else {if (endExclude > strLength) {endExclude = strLength;}if (startInclude > endExclude) {return originalStr;} else {StringBuilder stringBuilder = new StringBuilder();int i;for(i = 0; i < startInclude; ++i) {stringBuilder.append(new String(strCodePoints, i, 1));}stringBuilder.append(replacedStr);for(i = endExclude; i < strLength; ++i) {stringBuilder.append(new String(strCodePoints, i, 1));}return stringBuilder.toString();}}}}public static String subPre(CharSequence string, int toIndexExclude) {return sub(string, 0, toIndexExclude);}public static String sub(CharSequence str, int fromIndexInclude, int toIndexExclude) {if (isEmpty(str)) {return str(str);} else {int len = str.length();if (fromIndexInclude < 0) {fromIndexInclude += len;if (fromIndexInclude < 0) {fromIndexInclude = 0;}} else if (fromIndexInclude > len) {fromIndexInclude = len;}if (toIndexExclude < 0) {toIndexExclude += len;if (toIndexExclude < 0) {toIndexExclude = len;}} else if (toIndexExclude > len) {toIndexExclude = len;}if (toIndexExclude < fromIndexInclude) {int tmp = fromIndexInclude;fromIndexInclude = toIndexExclude;toIndexExclude = tmp;}return fromIndexInclude == toIndexExclude ? "" : str.toString().substring(fromIndexInclude, toIndexExclude);}}public static boolean isEmpty(CharSequence str) {return str == null || str.length() == 0;}public static String str(CharSequence cs) {return null == cs ? null : cs.toString();}/*** [中文姓名] 只显示第一个汉字,其他隐藏为星号<例子:李**>** @param fullName 姓名* @return*/public static String chineseName(String fullName) {if (StringUtils.isBlank(fullName)) {return "";}String name = StringUtils.left(fullName, 1);return StringUtils.rightPad(name, StringUtils.length(fullName), "*");}/*** [中文姓名] 只显示姓氏,其他隐藏为星号<例子:欧阳娜娜  : 欧阳**>** @param familyName 姓氏* @param givenName  名字* @return*/public static String chineseName(String familyName, String givenName) {if (StringUtils.isBlank(familyName) || StringUtils.isBlank(givenName)) {return "";}if (familyName.length() > 1) {String name = StringUtils.left(familyName, familyName.length());return StringUtils.rightPad(name, StringUtils.length(familyName + givenName), "*");}return chineseName(familyName + givenName);}/*** [身份证号] 显示最后四位,其他隐藏。共计18位或者15位。<例子:*************5762>** @param id* @return*/public static String idCardNum(String id) {if (StringUtils.isBlank(id)) {return "";}String num = StringUtils.right(id, 4);return StringUtils.leftPad(num, StringUtils.length(id), "*");}/*** [身份证号] 前六位,后四位,其他用星号隐藏每位1个星号<例子:451002********1647>** @param carId* @return*/public static String idCard(String carId) {if (StringUtils.isBlank(carId)) {return "";}return StringUtils.left(carId, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(carId, 4), StringUtils.length(carId), "*"), "******"));}/*** [固定电话] 后四位,其他隐藏<例子:****1234>** @param num* @return*/public static String fixedPhone(String num) {if (StringUtils.isBlank(num)) {return "";}return StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*");}/*** [手机号码] 前三位,后四位,其他隐藏<例子:138******1234>** @param num* @return*/public static String mobilePhone(String num) {if (StringUtils.isBlank(num)) {return "";}return StringUtils.left(num, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*"), "***"));}/*** [地址] 只显示到地区,不显示详细地址;我们要对个人信息增强保护<例子:北京市海淀区****>** @param address* @param sensitiveSize 敏感信息长度* @return*/public static String address(String address, int sensitiveSize) {if (StringUtils.isBlank(address)) {return "";}int length = StringUtils.length(address);return StringUtils.rightPad(StringUtils.left(address, length - sensitiveSize), length, "*");}/*** [电子邮箱] 邮箱前缀仅显示第一个字母,前缀其他隐藏,用星号代替,@及后面的地址显示<例子:g**@163.com>** @param email* @return*/public static String email(String email) {if (StringUtils.isBlank(email)) {return "";}int index = StringUtils.indexOf(email, "@");if (index <= 1) {return email;}return StringUtils.rightPad(StringUtils.left(email, 1), index, "*").concat(StringUtils.mid(email, index, StringUtils.length(email)));}/*** [银行卡号] 前六位,后四位,其他用星号隐藏每位1个星号<例子:6222600**********1234>** @param cardNum* @return*/public static String bankCard(String cardNum) {if (StringUtils.isBlank(cardNum)) {return "";}return StringUtils.left(cardNum, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(cardNum, 4), StringUtils.length(cardNum), "*"), "******"));}/*** [公司开户银行联号] 公司开户银行联行号,显示前两位,其他用星号隐藏,每位1个星号<例子:12********>** @param code* @return*/public static String cnapsCode(String code) {if (StringUtils.isBlank(code)) {return "";}return StringUtils.rightPad(StringUtils.left(code, 2), StringUtils.length(code), "*");}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/820284.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端三剑客 —— JavaScript (第十一节)

内容回顾&#xff1a; jQuery 操作DOM jQuery 事件处理 Ajax jQuery 特效案例 全选效果 tab切换 下拉菜单 自定义动画 Bootstrap 入门 首先我们可以在bootstrap官网上进行下载。官网地址:https//www.bootcss.com/ 首先在我们的页面中导入bootstrap的样式&#xff0c;我们可…

推荐系统综述

推荐系统研究综述 - 中国知网 传统推荐方法主要分类&#xff1a; 1)基于内容推荐方法 主要依据用户与项目之间的特征信息,用户之间的联系不会影响推荐结果,所以不存在冷启动和稀疏问题,但是基于内容推荐的结果新颖程度低并且面临特征提取的问题。 基于内容的推荐方法的思想非…

03-echarts如何画立体柱状图

echarts如何画立体柱状图 一、创建盒子1、创建盒子2、初始化盒子&#xff08;先绘制一个基本的二维柱状图的样式&#xff09;1、创建一个初始化图表的方法2、在mounted中调用这个方法3、在方法中写options和绘制图形 二、画图前知识1、坐标2、柱状图图解分析 三、构建方法1、创…

pyecharts 区县

from pyecharts.charts import Map from pyecharts import options # 准备地图对象 map Map() # 准备数据&#xff0c;注意准备的数据必须是准确的&#xff0c;比如北京智能写北京市&#xff0c;湖南只能写湖南省&#xff0c;香港只能写香港特别行政区&#xff0c;西藏只能写西…

GPT提示词分享 —— 解梦

&#x1f449; 对你描述的梦境进行解读。 我希望你能充当一个解梦者。我将给你描述我的梦&#xff0c;而你将根据梦中出现的符号和主题提供解释。不要提供关于梦者的个人意见或假设。只提供基于所给信息的事实性解释。 GPT3.5的回答 GPT3.5 &#x1f447; 感觉有点傻&#xf…

Slf4j+Log4j简单使用

Slf4jLog4j简单使用 文章目录 Slf4jLog4j简单使用一、引入依赖二、配置 log4j2.xml2.1 配置结构2.2 配置文件 三、使用四、使用MDC完成日志ID4.1 程序入口处4.2 配置文件配置打印4.3 多线程日志ID传递配置 五. 官网 一、引入依赖 <dependencies><dependency><g…

java:Java中的类与对象(多态篇)

目录 何为多态 多态的实现条件 多态特点 继承关系&#xff1a; 方法重写&#xff1a; 父类引用指向子类对象&#xff1a; 运行时类型确定方法调用&#xff1a; 重写 概念&#xff1a; 注意事项&#xff1a; 向下转型和向上转型 何为多态 多态的概念&#xff1a;通俗来说…

linux mount挂载终结方案,测试好再重启

一、背景 不懂挂载&#xff0c;又担心改写了配置而开不了及机&#xff0c;这篇文章给你信心 用 sudo mount -a 测试 二、原理 1、先用命令在终端确认三可以挂载 2、改写配置文件 /etc/fstab 三、步骤 1、列出可以挂载的 fdisk -l dev/sda1 2048 616447 6…

JavaScript教程(十六) --- 元编程

元编程 Proxy 和 Reflect 对象允许你拦截并自定义基本语言操作&#xff08;例如属性查找、赋值、枚举和函数调用等&#xff09;。借助这两个对象&#xff0c;你可以在 JavaScript 进行元级别的编程。 代理 Proxy 对象可以拦截某些操作并实现自定义行为。 例如获取一个对象上…

大数据建模理论

文章目录 一、数仓概述1、数据仓库概念1.1 概述1.2 数据仓库与数据库的区别1.3 技术选型和架构 2、数仓常见名词2.1 实体2.2 维度2.3 度量2.4 粒度2.5 口径2.6 指标2.7 标签2.8 自然键/持久键/代理键2.9 退化维度2.10 下钻/上卷2.11 数据集市 3、数仓名词之间关系3.1 实体表&am…

java-javafx在普通类里如何弹出javafx的弹窗或者窗口

java-javafx在普通类里如何弹出javafx的弹窗或者窗口 背景代码运行报错解决方法总结参考 背景 想要在一个普通类里弹出一个弹窗 代码 package sample.main;import javafx.application.Application; import javafx.application.Platform; import javafx.embed.swing.JFXPanel…

Spring 事务失效总结

前言 在使用spring过程中事务是被经常用的&#xff0c;如果不小心或者认识不做&#xff0c;事务可能会失效。下面列举几条 业务代码没有被Spring 容器管理 看下面图片类没有Componet 或者Service 注解。 方法不是public的 Transactional 注解只能用户public上&#xff0c…

李沐41_物体检测和数据集——自学笔记

边缘框 1.一个边缘框可以通过4个数字定义&#xff08;左上xy&#xff0c;右上xy&#xff0c;左下xy&#xff0c;右下xy&#xff09; 2.标注成本高 目标检测数据集 1.每行表示一个物体&#xff08;图片文件名、物体类别、边缘框&#xff09; 2.COCO&#xff1a;80物体、330…

RAG原理详解

什么是RAG 检索增强生成&#xff08;Retrieval Augmented Generation&#xff0c;简称RAG&#xff09;为大型语言模型&#xff08;LLMs&#xff09;提供了从某些数据源检索到的信息&#xff0c;以此作为生成答案的基础。简而言之&#xff0c;RAG是搜索LLM提示的结合&#xff0…

Mac用户必备神器:Default Folder X,让文件操作更快捷、更智能!

Default Folder X for Mac是一款功能强大的文件管理辅助工具&#xff0c;它为Mac用户带来了前所未有的文件操作体验。&#x1f31f; 无论是日常办公、学习还是娱乐&#xff0c;Default Folder X都能帮助你更高效地管理文件&#xff0c;让你的工作更加得心应手。&#x1f4bc; …

AD高速板设计(笔记)

Alt左键高亮某个器件或属性&#xff0c;点击任意位置取消高亮。 TP设置旋转角度为45度&#xff0c;即可选中器件按空格旋转时候每次旋转45度。 先画出想要割槽的区域&#xff0c;选中之后TVB即可开槽。 左右翻转电路板&#xff1a;VB DR打开规则设置 UFO对器件进行扇出&#…

Linux系统部署可视化数据多维表格APITable并实现无公网IP远程协同办公

&#x1f308;个人主页: Aileen_0v0 &#x1f525;热门专栏: 华为鸿蒙系统学习|计算机网络|数据结构与算法 ​&#x1f4ab;个人格言:“没有罗马,那就自己创造罗马~” #mermaid-svg-G5XdKx1vxX0o0PES {font-family:"trebuchet ms",verdana,arial,sans-serif;font-siz…

PHP回显语句详解

PHP中的回显语句是一种常见的输出数据到前端的方法&#xff0c;广泛应用于网页开发中。本文将深入探讨PHP中回显语句的各个方面&#xff0c;包括其基本用法、不同的回显方法、与其他语句的比较、性能考量以及一些高级用法和技巧。 1. 回显语句的基本用法 在PHP中&#xff0c;…

AVM 环视拼接方法介绍

0. 简介 关于车辆的全景环视系统网上已经有很多的资料&#xff0c;然而几乎没有可供参考的代码&#xff0c;这一点对入门的新人来说非常不友好。全景环视系统&#xff0c;又称AVM。在自动驾驶领域&#xff0c;AVM属于自动泊车系统的一部分&#xff0c;是一种实用性极高、可大幅…

面试题总结:HashMap底层原理

不仅仅是一道题&#xff0c;之后的某一天&#xff0c;它可能是破局的关键。 关于HashMap的知识点有哪些呢&#xff1f;分层次展示 1.基础知识&#xff1a; 存储键值对结构、底层数据结构、红黑树和链表 2.位运算与实现 位运算、put、get方法的实现 3.关于锁 segment锁和桶锁、线…