Reputation:
I have a method which takes a String as an argument and returns the MD5 value of the String as a String. However, when I use the method I get "Th method md5() is undefined for type String". I'm probably just too tired too see an error I made, could you help me?
public static String md5(String s) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(s.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1, digest);
return bigInt.toString(16);
} catch (Exception e) {
return null;
}
}
public void hashing() {
int counter = 0;
StringBuilder sb = new StringBuilder();
for (int i=0; i<slovo.length(); i++) {
if (slovo.charAt(i)=='_') {
sb.append(characters.charAt(array[counter]));
counter++;
}else {
sb.append(input.charAt(i));
}
}
if (sb.toString().md5()==hash) { //this is the line which is producing the error
}
System.out.println(sb.toString());
}
Upvotes: 1
Views: 441
Reputation: 391
A String object does not have the method md5(), and md5 takes in a single argument.
Did you mean md5(sb.toString())
?
Upvotes: 2