md5加密工具类

package cn.itcast.estore01.utils;

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

import java.security.NoSuchAlgorithmException;

public class MD5Utils {

  byte[] secretBytes = null;
   try {

      secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());

    } catch (NoSuchAlgorithmException e) {

    throw new RuntimeException("加密失败");
    }

  return new BigInteger(1, secretBytes).toString(16);

}

public static void main(String[] args) {
  System.out.println(md5("root"));// 63a9f0ea7bb98050796b649e85481845
  // 63a9f0ea7bb98050796b649e85481845
 }
}

posted @ 2016-10-19 21:44  超级南瓜露  阅读(463)  评论(0编辑  收藏  举报