I'm making a MD5 hash of a response, and then signing it with a shared secret.
For most calls this works, but strangely fails (Generates a MD5 hash different from the client) on the only two calls that bring a lot of content in the body.
Can this be because of the size of the body? or maybe because those calls return the content chunked
?
Any idea will be appreciated. Thanks a lot.
The hashing code (note that algorithm == MD5
and ENCODING == 'UTF-8'
):
private static byte[] hash(String toHash, String algorithm){
try{
MessageDigest dg = MessageDigest.getInstance(algorithm);
dg.update(toHash.getBytes(ENCODING));
return dg.digest();
}catch(Exception e){
throw new ApiInternalException("Error while hashing string: " + toHash,e);
}
}