项目中需要对支付密码打乱后进行二次分割保存
方法如下:
// 将加密过后的支付密码分隔
public static String[] splitString(String securityPassword)
{
String[] total = {"", ""};
int i = securityPassword.length() / 4;
int j = securityPassword.length() % 4;
String securityPassword1 = securityPassword.subSequence(0, i)
.toString();
String securityPassword2 = securityPassword.subSequence(i, 2 * i)
.toString();
String securityPassword3 = securityPassword.subSequence(2 * i, 3 * i)
.toString();
String securityPassword4 = securityPassword
.subSequence(3 * i, 4 * i + j).toString();
total[0] = securityPassword1 + securityPassword3;
total[1] = securityPassword2 + securityPassword4;
return total;
}
判断支付密码是否正确的时候
把传过来的支付密码先加密,在打乱分割。然后和数据库里面的字段进行比对,就可以了。
//测试代码:
public static void main(String[] args){
String securityPassword = "ds12fdsgfdgfd12gfdgfdgfd";
String[] strs = splitString(securityPassword);
System.out.println(strs[0]+"======="+strs[1]);
}