Jmeter Base64 + MD5 encryption

1,359 views
Skip to first unread message

eddi...@gmail.com

unread,
Jan 12, 2016, 11:24:13 PM1/12/16
to jmeter-plugins
I have JMETER Plugin install and can use both encryption in JSON POST for an API in a test. 

When I use the string below:
"${__base64Encode(${__MD5(${OTAId}${OTAPwd}"StartDate":"${Start_Date}"})})}", the encryption is success and return "ZGYzNTFhYWRlNWU2N2QzNDI1NjVlZDg4YWZmMGViYTA=".

But when I add more parameter like below, added [,"EndDate":"${End_Date}"]:
"${__base64Encode(${__MD5(${OTAId}${OTAPwd}"StartDate":"${Start_Date}","EndDate":"${End_Date}"})})}", JMETER Return the same result "ZGYzNTFhYWRlNWU2N2QzNDI1NjVlZDg4YWZmMGViYTA=". It didn't include the part after the comma which I newly add.

Is there any idea I can include the comma as the string for encryption?

Vincent Daburon

unread,
Jan 13, 2016, 3:40:04 AM1/13/16
to jmeter-plugins, eddi...@gmail.com
Hi,
Try to despecialise the comma character
likes \,  (slash + comma)

Regards.
Vincent D.

Eddie Wong Guo Jie

unread,
Jan 13, 2016, 3:52:35 AM1/13/16
to Vincent Daburon, jmeter-plugins
Hi Vincent,

Thanks for the reply, but it still didn't work for me after add a / .
Do you have any idea?

Regards,
Eddie Wong

Vincent Daburon

unread,
Jan 13, 2016, 4:21:44 AM1/13/16
to jmeter-plugins, vdab...@gmail.com, eddi...@gmail.com
Hi,
Do you add  a /, or \, ?

Vincent D.

Eddie Wong Guo Jie

unread,
Jan 13, 2016, 5:51:08 AM1/13/16
to Vincent Daburon, jmeter-plugins
Hi,

I added \, into the string, like this.
"${__base64Encode(${__MD5(${OTAId}${OTAPwd}"StartDate":"${Start_Date}"\,"EndDate":"${End_Date}"})})}"

Is it correct?

Regards,
Eddie Wong

Vincent Daburon

unread,
Jan 13, 2016, 6:00:18 AM1/13/16
to jmeter-plugins, vdab...@gmail.com, eddi...@gmail.com
It's seem correct
You could use intermediate variables for storing the results
likes :
var  sContact =
${OTAId}${OTAPwd}"StartDate":"${Start_Date}"\,"EndDate":"${End_Date}
var sMD5 =
${__MD5(sContact)}
var sBase64 =
${__base64Encode(sMD5)

Regards.
Vincent D.


Eddie Wong Guo Jie

unread,
Jan 13, 2016, 6:04:58 AM1/13/16
to Vincent Daburon, jmeter-plugins
Hi Vincent,

May i know how can i do that? I'm passing a request to my server in JSON format like this:

Inline image 1
How can i store variable for MD5 and then use in Base64? 

Regards,
Eddie Wong

gli...@gmail.com

unread,
Jan 13, 2016, 9:37:43 AM1/13/16
to jmeter-plugins, eddi...@gmail.com
I recall similar question recently

You need to escape your comma with back slash like: \,

${__base64Encode(${__MD5(${OTAId}${OTAPwd}"StartDate":"${Start_Date}"\,"EndDate":"${End_Date}",)},)}


Eddie Wong Guo Jie

unread,
Jan 13, 2016, 10:11:47 AM1/13/16
to gli...@gmail.com, jmeter-plugins
​thanks glinius,

I tried but it doesn't work in my case. I don't know why. Do you have any other idea to solve it?​

Regards,
Eddie Wong

Vincent Daburon

unread,
Jan 13, 2016, 10:56:01 AM1/13/16
to jmeter-plugins, vdab...@gmail.com, eddi...@gmail.com
Hi,
Add a Sampler JSR223 before your http sampler and select javascript language
In this sampler the javascript code :
var  sContact = '${OTAId}' + '${OTAPwd} ' + '"StartDate":' + '"${Start_Date}"' + ',' +  '"EndDate":' + '"${End_Date}"';

log.info("sContact = " + sContact);

vars.put("P_CONTACT",sContact);

var sMD5= "${__MD5(${P_CONTACT},P_MD5)}";

log.info("sMD5 = " + sMD5);

var sBase64 = "${__base64Encode(${P_MD5},P_ENCODED_CONTACT_B64)}";
log.info("sBase64 = " + sBase64);
log.info("P_ENCODED_CONTACT_B64 = " + vars.get("P_ENCODED_CONTACT_B64"));

// for verify the encoded result not mandatory
var sBase64Decoded = "${__base64Decode(${P_ENCODED_CONTACT_B64},P_DECODED_CONTACT_B64)}";
log.info("P_DECODED_CONTACT_B64 = " + vars.get("P_DECODED_CONTACT_B64"));

==============================================================
Use the ${P_ENCODED_CONTACT_B64} in your http sampler in  the JSON

Logs :
2016/01/13 16:51:57 INFO  - jmeter.protocol.java.sampler.JSR223Sampler: sContact = 1234thepasswordOTA "StartDate":"20160110","EndDate":"20160113"
2016/01/13 16:51:57 INFO  - jmeter.protocol.java.sampler.JSR223Sampler: sMD5 = f074b1bce39f8a0126809bb243966d0e
2016/01/13 16:51:57 INFO  - jmeter.protocol.java.sampler.JSR223Sampler: sBase64 = ZjA3NGIxYmNlMzlmOGEwMTI2ODA5YmIyNDM5NjZkMGU=
2016/01/13 16:51:57 INFO  - jmeter.protocol.java.sampler.JSR223Sampler: P_ENCODED_CONTACT_B64 = ZjA3NGIxYmNlMzlmOGEwMTI2ODA5YmIyNDM5NjZkMGU=
2016/01/13 16:51:57 INFO  - jmeter.protocol.java.sampler.JSR223Sampler: P_DECODED_CONTACT_B64 = f074b1bce39f8a0126809bb243966d0e

and result in a Debugg sampler :
JMeterVariables:
End_Date=20160113
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage@2f673724
OTAId=1234
OTAPwd=thepasswordOTA
P_CONTACT=1234thepasswordOTA "StartDate":"20160110","EndDate":"20160113"
P_DECODED_CONTACT_B64=f074b1bce39f8a0126809bb243966d0e
P_ENCODED_CONTACT_B64=ZjA3NGIxYmNlMzlmOGEwMTI2ODA5YmIyNDM5NjZkMGU=
P_MD5=f074b1bce39f8a0126809bb243966d0e
START.HMS=150930
START.MS=1452694170430
START.YMD=20160113
Start_Date=20160110
TESTSTART.MS=1452700316929


Regards.
Vincent D.

Eddie Wong Guo Jie

unread,
Jan 14, 2016, 8:46:48 AM1/14/16
to Vincent Daburon, jmeter-plugins
Hi Vincent,

Thanks very much, it work for me perfectly now!

Regards,
Eddie Wong
Reply all
Reply to author
Forward
0 new messages