UserGetResponse rsp = mapperFacademapuser UserGetResponseclass; rspsetTypeUserTypefromusergetTypegetName; rspsetMobileEncryptUtildecryptEncryptionTypeDES rspgetMobile; rspsetNameE
要将解密后的手机号码加密中间的四位号码为*,可以使用以下方法:
- 先将解密后的手机号码转换为字符数组。
- 对字符数组的中间四位进行替换为*操作。
- 将替换后的字符数组重新转换为字符串。
- 将加密后的手机号码设置到rsp对象的mobile属性中。
修改后的代码如下:
rsp.setMobile(encryptMiddleFour(EncryptUtil.decrypt(Encryption.Type.DES, rsp.getMobile())));
// ...
private String encryptMiddleFour(String mobile) {
char[] chars = mobile.toCharArray();
for (int i = 3; i < 7; i++) {
chars[i] = '*';
}
return new String(chars);
}
在上述代码中,encryptMiddleFour方法用于替换字符数组中中间四位为*,然后将替换后的字符数组转换为字符串返回。在setMobile方法中,调用encryptMiddleFour方法对解密后的手机号码进行加密处理
原文地址: http://www.cveoy.top/t/topic/hMrZ 著作权归作者所有。请勿转载和采集!