import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
/**
 * MD5+Base64加密
 * @author 于凤航
 */
public class Md5Base64 {
    public static String encode(String s) {
        if (s == null)
            return null;
        String encodeStr = "";
        byte[] utfBytes = s.getBytes();
        MessageDigest mdTemp;
        try {
            mdTemp = MessageDigest.getInstance("MD5");
            mdTemp.update(utfBytes);
            byte[] md5Bytes = mdTemp.digest();
            BASE64Encoder b64Encoder = new BASE64Encoder();
            encodeStr = b64Encoder.encode(md5Bytes);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        return encodeStr;
    }
    public static void main(String[] args) {
        System.out.println(Md5Base64.encode("123456"));
    }
}