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