package com.zhangpan.cn;import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import sun.misc.BASE64Encoder;public class EncryptMd5Util {/** * Method:MD5加密String * Date:2017年9月5日下午4:50:55 * Author:ZhangPan */public static String encoderByMd5(String password) {String encryptPwd=null;try {MessageDigest md5 = MessageDigest.getInstance("MD5");BASE64Encoder base64en = new BASE64Encoder();encryptPwd = base64en.encode(md5.digest(password.getBytes("utf-8")));} catch (NoSuchAlgorithmException e) {e.printStackTrace();} catch (UnsupportedEncodingException e) {e.printStackTrace();}return encryptPwd;}public static void main(String[] args) {String pwd= EncryptMd5Util.encoderByMd5("123456");String pwd1= EncryptMd5Util.encoderByMd5("zhangpan");String pwd2= EncryptMd5Util.encoderByMd5("zengnana");String pwd3= EncryptMd5Util.encoderByMd5("张盼");String pwd4= EncryptMd5Util.encoderByMd5("曾娜娜");System.out.println("[123456]MD5加密转换后:"+"["+pwd+"]");System.out.println("[zhangpan]MD5加密转换后:"+"["+pwd1+"]");System.out.println("[zengnana]MD5加密转换后:"+"["+pwd2+"]");System.out.println("[张盼]MD5加密转换后:"+"["+pwd3+"]");System.out.println("[曾娜娜]MD5加密转换后:"+"["+pwd4+"]");}}
MD5加密String
最新推荐文章于 2023-03-10 14:44:44 发布