Create MD5 hash in transformation script


I’m testing a mecross switch with MQTT & openhab, and it’s almost working. I have one last step, which is to create an MD5 hash of some values to sign the JSON payload in a javascript transform script.

My script so far:

(function(state) {
	var logger = Java.type("org.slf4j.LoggerFactory").getLogger("myScript");
	logger.warn("mecross.js - start");

	var message = "messsage" +;
	var timestamp = / 100;

	var result = {};
	result.header = {};
	result.header.messageId = message;
	result.header.namespace = "Appliance.Control.ToggleX";
	result.header.method = "SET";
	result.header.payloadVersion = 1;
	result.header.from = "/appliance/openhab/ack";
	result.header.timestamp = timestamp;
	result.header.sign = MD5(message+timestamp).toString();

	result.payload = {}
	result.payload.togglex = {}; = 0;
	result.payload.togglex.onoff = state == "1"?1:0;

	return JSON.stringify(result);


My issue is with the following line:

result.header.sign = MD5(message+timestamp).toString();

I need a function to create the MD5 hash — Does one exist? Or do I need to create my own?

Thank you.


I found a pure JavaScript implementation of MD5 online and used that to create a script.

For reference, the script is here:

Also, I created a small article on configuring Meross switches with openhab: