I need to generate a hashed string(md5 or sha-1 or whatever) which doesn't contain a comma or next line because I'm storing with some more data in a csv file. I've tried, after generating md5 normally, replacing all occurrences of ',' and '\n' by String.replace, but somehow, there are still some newline characters or some characters that behave like newline. Is there a way, to generates only alphabets and numbers in the string while encrypting?
Edit: I realised that what I am asking for is a bad thing because it'll make 'abcd,' and ',abcd' same, as pointed out by GhostCat. Actually, it's not production environment and I just need some of hashing that produces consistent result for each input, and to be able to save it in csv files.
This is my code.
public static String hashPassword(String password)
{
MessageDigest md=null;
try {
md=MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
String passwd=new String (md.digest(password.getBytes()));
//To convert it to ',' so that it'll be removed with other ',''s
passwd=passwd.replace('\n',',');
passwd=passwd.replace(",","");
return passwd;
}