I wanted to generate a unique hash code for a string in put in android. Is there any predefined library is there or we have to generate manually. Please any body if knows pl
You can use this code for generating has code for a given string.
int hash = 7;
for (int i = 0; i < strlen; i++) {
hash = hash*31 + charAt(i);
}
I use this i tested it as key from my EhCacheManager
Memory map ....
Its cleaner i suppose
/**
* Return Hash256 of String value
*
* @param text
* @return
*/
public static String getHash256(String text) {
try {
return org.apache.commons.codec.digest.DigestUtils.sha256Hex(text);
} catch (Exception ex) {
Logger.getLogger(HashUtil.class.getName()).log(Level.SEVERE, null, ex);
return "";
}
}
am using maven but this is the jar commons-codec-1.9.jar