package com.wuzy.web.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.UUID; import sun.misc.BASE64Encoder; public class DigestUtil { /** * MD5加密 * @param psw * @return */ public static String digestMD5(String psw){ MessageDigest md; try { //將原字符串采用MD5加密成byte[] md = MessageDigest.getInstance("MD5"); byte[] bbs = md.digest(psw.getBytes()); //采用Base64算法將byte[]編碼成字符串 BASE64Encoder base64 = new BASE64Encoder(); String s = base64.encode(bbs); return s; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } public static void main(String[] args){ String s = DigestUtil.digestMD5("abc"); System.out.println(s); s = DigestUtil .digestMD5("123456dfdfgdf"); System.out.println(s); } } |
|
來(lái)自: 時(shí)時(shí)Java圖書(shū) > 《待分類》