当前位置:网站首页>附加:信息脱敏;
附加:信息脱敏;
2022-07-02 02:05:00 【小枯林】
说明:
(1)为什么写了本篇博客?:
● 在【26:第三章:开发通行证服务:9】中,我们新增AppUser数据的时候,设置用户昵称的时候,编写了一个信息脱敏工具DesensitizationUtil工具类;(可以把【用户+18888888888】转化为【用户+18******888】的形式);
● 本篇博客就来介绍下信息脱敏工具DesensitizationUtil;
(2)其实,本篇博客主要是让自己明确两点:
● 对于项目中,一些需要在前台展示,但同时又不想泄密的情况,可以考虑信息脱敏;
● 然后,本篇博客,只是一个信息脱敏的案例而已;对于其他项目,虽然有信息脱敏需求,但是这个需求却各有不同(比如有的要求把18888888888转成18***888***;有的要求把18888888888转成18######888;有的要求把李二柱转成李*柱等)
(3)以后,在其他项目中,遇到具体的信息脱敏需求时,再根据实际情况,编写具体的、适合的逻辑去解决就行了;
目录
一:在【26:第三章:开发通行证服务:9】中,DesensitizationUtil工具类的内容;
一:在【26:第三章:开发通行证服务:9】中,DesensitizationUtil工具类的内容;
package com.imooc.utils; /** * 通用脱敏工具类 * 可用于: * 用户名 * 手机号 * 邮箱 * 地址等 */ public class DesensitizationUtil { private static final int SIZE = 6; private static final String SYMBOL = "*"; public static void main(String[] args) { String name = commonDisplay("慕课网"); String mobile = commonDisplay("13900000000"); String mail = commonDisplay("[email protected]"); String address = commonDisplay("北京大运河东路888号"); System.out.println(name); System.out.println(mobile); System.out.println(mail); System.out.println(address); } /** * 通用脱敏方法 * @param value * @return */ public static String commonDisplay(String value) { if (null == value || "".equals(value)) { return value; } int len = value.length(); int pamaone = len / 2; int pamatwo = pamaone - 1; int pamathree = len % 2; StringBuilder stringBuilder = new StringBuilder(); if (len <= 2) { if (pamathree == 1) { return SYMBOL; } stringBuilder.append(SYMBOL); stringBuilder.append(value.charAt(len - 1)); } else { if (pamatwo <= 0) { stringBuilder.append(value.substring(0, 1)); stringBuilder.append(SYMBOL); stringBuilder.append(value.substring(len - 1, len)); } else if (pamatwo >= SIZE / 2 && SIZE + 1 != len) { int pamafive = (len - SIZE) / 2; stringBuilder.append(value.substring(0, pamafive)); for (int i = 0; i < SIZE; i++) { stringBuilder.append(SYMBOL); } if ((pamathree == 0 && SIZE / 2 == 0) || (pamathree != 0 && SIZE % 2 != 0)) { stringBuilder.append(value.substring(len - pamafive, len)); } else { stringBuilder.append(value.substring(len - (pamafive + 1), len)); } } else { int pamafour = len - 2; stringBuilder.append(value.substring(0, 1)); for (int i = 0; i < pamafour; i++) { stringBuilder.append(SYMBOL); } stringBuilder.append(value.substring(len - 1, len)); } } return stringBuilder.toString(); } }说明:
(1)这个代码,自己并没有细看;但稍微瞅了一眼,其基本思路就是:在考虑了所有非正常情况后,把18888888888转成18******888;
边栏推荐
- Construction and maintenance of business websites [13]
- The concept, function, characteristics, creation and deletion of MySQL constraints
- Laravel artisan common commands
- leetcode373. Find and minimum k-pair numbers (medium)
- np. Where and torch Where usage
- Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing
- JMeter (I) - download, installation and plug-in management
- How does MySQL solve the problem of not releasing space after deleting a large amount of data
- [question] - why is optical flow not good for static scenes
- Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
猜你喜欢

Discussion on the idea of platform construction

This is the form of the K-line diagram (pithy formula)

MATLAB realizes voice signal resampling and normalization, and plays the comparison effect

5g/4g pole gateway_ Smart pole gateway

How to execute an SQL in MySQL

leetcode2305. 公平分发饼干(中等,周赛,状压dp)

MySQL约束与多表查询实例分析

Volume compression, decompression

Redis有序集合如何使用

A quick understanding of digital electricity
随机推荐
牛客网——华为题库(51~60)
【LeetCode 43】236. The nearest common ancestor of binary tree
Based on configured schedule, the given trigger will never fire
Based on configured schedule, the given trigger will never fire
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
leetcode373. 查找和最小的 K 对数字(中等)
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Openssl3.0 learning XXI provider encoder
leetcode2305. 公平分发饼干(中等,周赛,状压dp)
Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
This is the form of the K-line diagram (pithy formula)
Parted command
MySQL主从延迟问题怎么解决
How to use a product to promote "brand thrill"?
城市选择器组件实现原理
Six lessons to be learned for the successful implementation of edge coding
如何用一款产品推动「品牌的惊险一跃」?
How to debug apps remotely and online?
Architecture evolution from MVC to DDD
Construction and maintenance of business websites [14]
