public static String hash(String str, String algorithm, int numIterations,char[] encoding) throws NoSuchAlgorithmException {
try {
MessageDigest md=MessageDigest.getInstance(algorithm),mdc;
for(int i=0;i<numIterations;i++){
mdc=(MessageDigest) md.clone();
mdc.reset();
mdc.update(toBytes(str, CharsetUtil.UTF8));
str=new String(enc(mdc.digest(),encoding));
}
return str;