Answer the question
In order to leave comments, you need to log in
How to solve the error (incomprehensible problem with MessageDigest)?
In general, I made a json request, or rather redid it with the help, and everything seems to be fine, everything works in the console, sends the request and the answer comes that everything has come to the server, but when I started putting it in my application I ran into an incomprehensible error. I started to figure it out and killed for more than 4 hours, which did not give a result. The problem is that it throws it out of the application when, after forming the md5 string, it tries to return the result, but it seems to me that the problem is that the string itself is formed by different libraries (or how to call it correctly). The console application (which works) generates a MessageDigest using java (on IntelliJ IDEA), and my application that I wrote on android studio using apache .
Here is a screenshot from IntelliJ IDEA:
here is a screenshot from android studio:
and here is the function itself in which it all happens:
public static String toHash(String input, HashType hashType) {
// Create MD5 Hash
java.security.MessageDigest md=null;
String preHash;
StringBuffer hexString = new StringBuffer();
try {
md = MessageDigest.getInstance("MD5");
md = MessageDigest.getInstance(hashType.algorithm);
//md5.reset();
md.update(input.getBytes());
byte[] messageDigest = md.digest();
for (int i = 0; i < messageDigest.length; i++) {
preHash = Integer.toHexString(0xFF & messageDigest[i]);
if (preHash.length() < 2) {
preHash = "0" + preHash;
}
hexString.append(preHash);
}
} catch (NoSuchAlgorithmException e) {
return e.toString();
}
return hexString.toString();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question