当前位置 : 主页 > 编程语言 > java >

Md5util

来源:互联网 收集:自由互联 发布时间:2021-06-28
Md5util.java public class Md5util {private static StringBuffer stringBuffer;public static String encoder(String psd){psd = "mutisafe" + psd + "@leafotto.tk";try {//指定加密算法MessageDigest digest = MessageDigest.getInstance("MD5");//将
Md5util.java
public class Md5util {

	private static StringBuffer stringBuffer;

	public static String encoder(String psd){
		psd = "mutisafe" + psd + "@leafotto.tk";
		try {
			//指定加密算法
			MessageDigest digest = MessageDigest.getInstance("MD5");
			//将需要加密的字符串转换成byte类型的数组,然后进行随机哈希
			byte[] bs = digest.digest(psd.getBytes());
			//循环遍历bs,然后让其生成32位字符串,固定写法
			stringBuffer = new StringBuffer();
			for(byte b : bs){
				int i = b & 0xff;
				String hexString = Integer.toHexString(i);
				if(hexString.length() < 2){
					hexString = "0" + hexString;
				}
				//拼接字符串
				stringBuffer.append(hexString);
			}
			return stringBuffer.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return "";
	}
}
上一篇:CS-LuceneIndexer
下一篇:时间类
网友评论