JMeter's BeanShell Sampler

Source: Internet
Author: User
Tags md5 encryption stringbuffer

Transferred from: http://www.cnblogs.com/tester-hehehe/p/5466364.html

Content

1. First write the code in Eclipse and execute it with eclipse to make sure the file doesn't get an error.

Str2md5.java content is as follows:

PackageHEHE.MD5;ImportJava.security.MessageDigest;ImportJava.security.NoSuchAlgorithmException;PublicClassSTR2MD5 {PublicString MD5 (String sourcestr) {string result = "";Try{MessageDigest MD = messagedigest.getinstance ("MD5"); Md.update (Sourcestr.getbytes ());byte b[] =Md.digest ();IntI StringBuffer buf =New StringBuffer ("");for (int offset = 0; Offset < b.length; offset++) {i = b[offset]; if (i < 0) i + = +; if (i <)Buf.append ("0"); Buf.append (integer.tohexstring (i));} result = buf.tostring (); System.out.println ("MD5 (" + Sourcestr + ", +) =" + result "); // System.out.println ("MD5 (" + Sourcestr + ", +) =" + buf.tostring (). SUBSTRING (8, 24));} Catch (NoSuchAlgorithmException e) {System.out.println (e);} return result;}}               

2. Export the file and place it in the JM lib/ext file directory

3, in the JM inside call

Import hehe.md5.  STR2MD5; new Str2md5 (). MD5 ("ADF"); System.out.println (res); Vars.put ("MD5", res.tostring ());  

Look at the results.

This can be quoted in the JM variable and parameters can be parameterized. In fact, simple MD5 encryption in the JM inside a function can be called directly. _MD5 ()

JMeter's BeanShell Sampler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.