当前位置:网站首页>附加:信息脱敏;
附加:信息脱敏;
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;
边栏推荐
- Makefile simple induction
- Bash bounce shell encoding
- Deep learning: a solution to over fitting in deep neural networks
- Design and implementation of key value storage engine based on LSM tree
- How to turn off debug information in rtl8189fs
- 【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
- Number of palindromes in C language (leetcode)
- MySQL约束与多表查询实例分析
- 【C#】使用正则校验内容
- This is the form of the K-line diagram (pithy formula)
猜你喜欢
JMeter (II) - install the custom thread groups plug-in
leetcode373. Find and minimum k-pair numbers (medium)
How to execute an SQL in MySQL
Four basic strategies for migrating cloud computing workloads
Implementation of Weibo system based on SSM
Opengauss database backup and recovery guide
How to use a product to promote "brand thrill"?
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
479. Additive binary tree (interval DP on the tree)
5g/4g pole gateway_ Smart pole gateway
随机推荐
Automatically browse pinduoduo products
剑指 Offer 31. 栈的压入、弹出序列
[graduation season] graduate seniors share how to make undergraduate more meaningful
MySQL如何解决delete大量数据后空间不释放的问题
flutter 中间一个元素,最右边一个元素
What are the necessary things for students to start school? Ranking list of Bluetooth headsets with good sound quality
How to use a product to promote "brand thrill"?
The concept, function, characteristics, creation and deletion of MySQL constraints
Learn basic K-line diagram knowledge in three minutes
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
医药管理系统(大一下C语言课设)
"C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure
The concepts and differences between MySQL stored procedures and stored functions, as well as how to create them, the role of delimiter, the viewing, modification, deletion of stored procedures and fu
电子协会 C语言 1级 32、计算2的幂
Ar Augmented Reality applicable scenarios
Post infiltration flow encryption
AR增强现实可应用的场景
Iterative unified writing method of binary tree
Construction and maintenance of business websites [14]
Four basic strategies for migrating cloud computing workloads