zoukankan      html  css  js  c++  java
  • 信息脱敏

    package com.wisoft.tysfrz.utils;
    
    
    public class SensitiveInfoUtils {
        private static final int SIZE = 6;
        private static final String SYMBOL = "*";
        @SuppressWarnings("unused")
        public static String toConceal(String value) {
            if (null == value || "".equals(value)) {
                return value;
            }
            value = value.replace("@", "").replace("-", "");
            int len = value.length();
            int pamaone = len / 2;
            int pamatwo = pamaone - 1;
            int pamathree = len % 2;
            StringBuilder stringBuilder = new StringBuilder();
            if (len == 2) {//两个字的姓名
                stringBuilder.append(value.substring(0, 1)+SYMBOL);
                return stringBuilder.toString();
            }
            if (len == 3) {//三个字的姓名
                stringBuilder.append(value.substring(0, 1)+SYMBOL+SYMBOL);
                return stringBuilder.toString();
            }
            if (len == 18) {//18位身份证号码
                stringBuilder.append(value.substring(0, SIZE));
                for (int i = 0; i < 8; i++) {
                    stringBuilder.append(SYMBOL);
                }
                stringBuilder.append(value.substring(len-4));
                return stringBuilder.toString();
            }
            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();
        }
        public static void main(String args[]) {
            String zoneCode = PropertiesUtil.getValue("system.zoneCode");
            System.out.println(zoneCode);
            String str = "329323198009132424";
            String strname1 = "15123569859";
            String strname2 = "张三";
            String strname3 = "张三四风";
            String strname4 = "张三风";
            String strname5 = "张";
            String strname6 = "jaddy1@1256.com";
            System.out.println(SensitiveInfoUtils.toConceal(str));
            System.out.println(SensitiveInfoUtils.toConceal(strname1));
            System.out.println(SensitiveInfoUtils.toConceal(strname2));
            System.out.println(SensitiveInfoUtils.toConceal(strname3));
            System.out.println(SensitiveInfoUtils.toConceal(strname4));
            System.out.println(SensitiveInfoUtils.toConceal(strname5));
            System.out.println(SensitiveInfoUtils.toConceal(strname6));
        }
    }
  • 相关阅读:
    MySQL学习笔记(六):索引
    正则表达式基础知识,持续更新…
    js改变盒子大小(上下左右)分析
    表单自定义样式
    js拖拽分析
    javascript右键菜单分析
    简要分析javascript的选项卡和轮播图
    表单联动的总结
    浅显总结ASCII Unicode UTF-8的区别
    瀑布流知识的延伸
  • 原文地址:https://www.cnblogs.com/jassy/p/7509105.html
Copyright © 2011-2022 走看看