I need to obfuscate values of parameters matching
password, tokenID
Sample query string:
visitorNo=89&password=demo&tokenID=yxr56
Should be obfuscated to:
visitorNo=89&password=$$&tokenID=$$
What I did:
String[] parameters = queryString.split("&");
StringBuffer qS = new StringBuffer();
for(String param : parameters) {
String[] keyValue = param.split("=");
qS.append(keyValue[0]);
qS.append("=");
for(String paramToObfuscate : paramsToObfuscate) {
if(paramToObfuscate.equals(keyValue[0])) {
qS.append("$$");
}
else {
qS.append(keyValue[1]);
}
}
qS.append("&");
}
String queryStr = qS.toString().substring(0, qS.length-1);
For only two parameters, there's no faster way. If there were tens of them, you could use
Set<String> paramsToObfuscate = new HashSet<String>();
and Set.contains
, which is surely faster than tens of tests.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments