package com.yx.face.boot.uitls;

import com.alibaba.excel.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: airport-review-smoke
 * @Package: com.yixin.review.boot.uitls
 * @ClassName: IDCardEncryptionUtil
 * @Author: 崔哥
 * @Description: 身份证加密
 * @Date: 2021/9/6 9:28
 * @Version: 1.0
 */
@Slf4j
public class IDCardEncryptionUtil {


    // 手机号码前三后四脱敏
    public static String mobileEncrypt(String mobile) {
        if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) {
            return mobile;
        }
        return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    //身份证前六后四脱敏
    public static String idEncrypt(String id) {
        if (StringUtils.isEmpty(id) || (id.length() < 8)) {
            return id;
        }
        return id.replaceAll("(?<=\\w{6})\\w(?=\\w{4})", "*");
    }

    //护照前2后3位脱敏，护照一般为8或9位
    public static String idPassport(String id) {
        if (StringUtils.isEmpty(id) || (id.length() < 8)) {
            return id;
        }
        return id.substring(0, 2) + new String(new char[id.length() - 5]).replace("\0", "*") + id.substring(id.length() - 3);
    }


    public static void main(String[] args) {
        String ino = "513722587956565455";
        String s = idEncrypt(ino);
        System.out.println(s);
    }


}
