标签:
.net 代码
/// <summary> /// MD5加密 /// </summary> /// <param name="encryptStr">明文字符</param> /// <returns>加密字符</returns> public static string Md5Encrypt(string encryptStr) { string str = string.Empty; MD5 md5 = MD5.Create(); byte[] encryptBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(encryptStr)); for (int i = 0; i < encryptBytes.Length; i++) { str += encryptBytes[i].ToString("x2"); } return str; }
java 代码
/** * MD5加密 * @param encryptStr 明文字符 * @return 加密字符 */ public static String Md5Encrypt(String encryptStr) { String str = ""; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] encryptBytes = md5.digest(encryptStr.getBytes("UTF-8")); StringBuffer hexValue = new StringBuffer(); for (int i = 0; i < encryptBytes.length; i++) { int val = ((int) encryptBytes[i]) & 0xff; if (val < 16) { hexValue.append("0"); } hexValue.append(Integer.toHexString(val)); } str = hexValue.toString(); } catch (Exception e) { e.printStackTrace(); } return str; }
标签:
原文地址:http://www.cnblogs.com/sealovesky99/p/5157892.html