当前位置:网站首页>附加:信息脱敏;
附加:信息脱敏;
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;
边栏推荐
- 电子协会 C语言 1级 32、计算2的幂
- Failed to transform file 'xxx' to match attributes
- 剑指 Offer 47. 礼物的最大价值
- Six lessons to be learned for the successful implementation of edge coding
- 牛客网——华为题库(51~60)
- Sword finger offer 47 Maximum value of gifts
- 479. Additive binary tree (interval DP on the tree)
- leetcode2305. Fair distribution of biscuits (medium, weekly, shaped pressure DP)
- Experimental reproduction of variable image compression with a scale hyperprior
- Sword finger offer 29 Print matrix clockwise
猜你喜欢

【LeetCode 43】236. The nearest common ancestor of binary tree

AR增强现实可应用的场景

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

479. Additive binary tree (interval DP on the tree)

JPM 2021 most popular paper released (with download)

golang---锁

如何远程、在线调试app?

How to turn off debug information in rtl8189fs

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

Four basic strategies for migrating cloud computing workloads
随机推荐
How to solve MySQL master-slave delay problem
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Exception handling of class C in yyds dry goods inventory
new和malloc的区别
Iterative unified writing method of binary tree
Construction and maintenance of business websites [13]
Bash bounce shell encoding
大学的知识是否学而无用、过时?
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
Volume compression, decompression
自动浏览拼多多商品
How to execute an SQL in MySQL
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
Opengauss database backup and recovery guide
如何远程、在线调试app?
* and & symbols in C language
VARIATIONAL IMAGE COMPRESSION WITH A SCALE HYPERPRIOR文献实验复现
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology
Cross domain? Homology? Understand what is cross domain at once
[question] - why is optical flow not good for static scenes
