Looks like the call to MessageDigest.digest() in CommunityCommons is used incorrectly. There are 3 overloads to this method, and the one used just returns the number of bytes used in the hash output buffer. The other two overloads return the hashed content.
I've uploaded a fixed StringUtils.java file here. You can overwrite the existing file in your project directory at:
\javasource\communitycommons\
I also commented on this issue and provided my code on github
Since I couldn't get the CommunityCommons to work as expected, I've created my own SHA-256 function, based on this post. This function does give me the expected result...
// BEGIN USER CODE
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(Value.getBytes());
byte[] digest = md.digest();
StringBuffer sb = new StringBuffer();
for (byte b : digest) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
// END USER CODE
Try implementing your own. Here's one that you can use a reference. It takes a strin as input and returns an integer/long
import com.mendix.systemwideinterfaces.core.UserAction; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction;
/**
*/ public class GetHash extends CustomJavaAction<long> { private String input;
public GetHash(IContext context, String input)
{
super(context);
this.input = input;
}
@Override
public Long executeAction() throws Exception
{
// BEGIN USER CODE
return Long.valueOf(input.hashCode());
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@Override
public String toString()
{
return "GetHash";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
Hi Eric,
great, thanks. but the uploaded StringUtils.java file seems to be identical to the one I already have... Perhaps you uploaded the wrong file?