MD5加密代码

package com.albedo.security;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * MD5加密
 */
public class Md5Utils {
    public static String encrypt(String plainText) throws Exception{
        byte[] secretBytes  = MessageDigest.getInstance("md5").digest(
                    plainText.getBytes());

        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }

}

 

posted @ 2020-09-11 15:14  重设代码的天空  阅读(420)  评论(0编辑  收藏  举报