md5+BASE64加密

import sun.misc.BASE64Encoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CryptUtil {
 private static final String KEY_MD5 = "MD5";
 public CryptUtil() {

 }
public static String MD5(String password) {
 String encodeStr = "";
 if (password == null){
  return null;
 }
 byte[] utfBytes = password.getBytes();
 MessageDigest md;
 try {
    md = MessageDigest.getInstance(KEY_MD5);
    md.update(utfBytes);
    byte[] md5Bytes = md.digest();
    BASE64Encoder b64Encoder = new BASE64Encoder();
    encodeStr = b64Encoder.encode(md5Bytes);
 } catch (NoSuchAlgorithmException e) {
   return null;
 }
   return encodeStr;
 }
}
 

 

 

你可能感兴趣的:(MD5)