Write MD5 encryption method in Java language. How does JMeter encrypt string MD5

 package md5package;

import java. io. UnsupportedEncodingException; import java. security. MessageDigest; import java. security. NoSuchAlgorithmException;

public class String2md5 {

public static void main(String args[]) {
    String aaa=StringToMd5("abc");

    if(aaa.equals("900150983cd24fb0d6963f7d28e17f72"))
    Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.out.println("MD5加密后的值是:"+aaa);
    else
        Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.out.println("-----sorry-"+aaa);

}

public static String StringToMd5(String psw) {  
    {  
        try {  
            MessageDigest md5 = MessageDigest.getInstance("MD5");  
            md5.update(psw.getBytes("UTF-8"));  
            byte[] encryption = md5.digest();  

            StringBuffer strBuf = new StringBuffer();  
            for (int i = 0; i < encryption.length; i++) {  
                if (Integer.toHexString(0xff &amp; encryption[i]).length() == 1) {  
                    strBuf.append("0").append(Integer.toHexString(0xff &amp; encryption[i]));  
                } else {  
                    strBuf.append(Integer.toHexString(0xff &amp; encryption[i]));  
                }  
            }  

            return strBuf.toString();  
        } catch (NoSuchAlgorithmException e) {  
            return "";  
        } catch (UnsupportedEncodingException e) {  
            return "";  
        }  
    }  
}  

}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>