当前位置:网站首页>附加:信息脱敏;
附加:信息脱敏;
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;
边栏推荐
- 剑指 Offer 47. 礼物的最大价值
- 如何远程、在线调试app?
- Niuke - Huawei question bank (51~60)
- Sword finger offer 29 Print matrix clockwise
- MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
- [deep learning] Infomap face clustering facecluster
- WebGPU(一):基本概念
- Design and implementation of key value storage engine based on LSM tree
- Sword finger offer 31 Stack push in and pop-up sequence
- Architecture evolution from MVC to DDD
猜你喜欢

How to solve MySQL master-slave delay problem

Ar Augmented Reality applicable scenarios

What is the MySQL column to row function

What is AQS and its principle

leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)

跨域?同源?一次搞懂什么是跨域

This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable

Redis环境搭建和使用的方法

如何远程、在线调试app?

1069. Division of convex polygons (thinking, interval DP)
随机推荐
C language 3-7 daffodils (enhanced version)
Iterative unified writing method of binary tree
软件开发生命周期 --瀑布模型
new和malloc的区别
MySQL constraints and multi table query example analysis
Six lessons to be learned for the successful implementation of edge coding
Bash bounce shell encoding
Using mongodb in laravel
Construction and maintenance of business websites [12]
mysql列转行函数指的是什么
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
Three core problems of concurrent programming
分卷压缩,解压
1222. Password dropping (interval DP, bracket matching)
Opencascade7.6 compilation
How to use a product to promote "brand thrill"?
With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry
The middle element and the rightmost element of the shutter
Redis有序集合如何使用
Ks006 student achievement management system based on SSM
