Here you can find the source of encryptBankCardNo(String cardNo)
public static String encryptBankCardNo(String cardNo)
//package com.java2s; //License from project: Apache License public class Main { private static final int DEFAULT_CARD_NUMBER_DISPLAY_LENGTH = 4; public static String encryptBankCardNo(String cardNo) { if (cardNo == null || cardNo.length() <= DEFAULT_CARD_NUMBER_DISPLAY_LENGTH) { return cardNo; }// w w w. ja v a 2s . c o m String preStr = cardNo.substring(DEFAULT_CARD_NUMBER_DISPLAY_LENGTH, cardNo.length() - DEFAULT_CARD_NUMBER_DISPLAY_LENGTH); preStr = preStr.replaceAll(".", "*"); return cardNo.substring(0, DEFAULT_CARD_NUMBER_DISPLAY_LENGTH).concat(preStr) .concat(cardNo.substring(cardNo.length() - DEFAULT_CARD_NUMBER_DISPLAY_LENGTH)); } }