package com.nd.util; import java.security.MessageDigest; public class MD5Utils { //ʮ����������ֵ��ַ��ӳ������ private final static String[] hexDigits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; /** * ��inputString���� */ public static String generatePassword(String inputString){ return encodeByMD5(inputString); } /** * ��֤����������Ƿ���ȷ * @param password ���ܺ������ * @param inputString ������ַ� * @return ��֤���TRUE:��ȷ FALSE:���� */ public static boolean validatePassword(String password, String inputString){ if(password.equals(encodeByMD5(inputString))){ return true; } else{ return false; } } /** ���ַ����MD5���� */ private static String encodeByMD5(String originString){ if (originString != null){ try{ //��������ָ���㷨��Ƶ���ϢժҪ MessageDigest md = MessageDigest.getInstance("MD5"); //ʹ��ָ�����ֽ������ժҪ���������£�Ȼ�����ժҪ���� byte[] results = md.digest(originString.getBytes()); //���õ����ֽ��������ַ��� String resultString = byteArrayToHexString(results); return resultString.toUpperCase(); } catch(Exception ex){ ex.printStackTrace(); } } return null; } /** * ת���ֽ�����Ϊʮ������ַ� * @param �ֽ����� * @return ʮ������ַ� */ private static String byteArrayToHexString(byte[] b){ StringBuffer resultSb = new StringBuffer(); for (int i = 0; i < b.length; i++){ resultSb.append(byteToHexString(b[i])); } return resultSb.toString(); } /** ��һ���ֽ�ת����ʮ�������ʽ���ַ� */ private static String byteToHexString(byte b){ int n = b; if (n < 0) n = 256 + n; int d1 = n / 16; int d2 = n % 16; return hexDigits[d1] + hexDigits[d2]; } public static void main(String args[]){ System.out.println(MD5Utils.encodeByMD5("123456")); } }

wda2399123 LV1
2024年7月25日
最代码温柔 LV18
2024年5月17日
xp95323 LV15
2023年10月30日
是夜在熬我. LV6
2022年11月30日
1641426181 LV4
2022年11月9日
testuser1234567 LV24
2022年7月21日
2716804680 LV9
2022年7月16日
zhaoyangwfd LV17
2022年6月16日
ming_123_9715 LV23
2022年6月8日
wsgwly LV6
2022年6月6日

yfb790910 LV3
2024年12月20日
yz8848 LV10
2024年9月21日
xiao小果 LV13
2024年8月28日
啦啦啦7719 LV15
2024年8月1日
wda2399123 LV1
2024年7月25日
wenjie_5419 LV13
2024年7月10日
liyan54188 LV2
2024年6月25日
微信网友_7017662097526784
2024年5月31日
暂无贡献等级
最代码温柔 LV18
2024年5月17日
wz LV3
2024年4月24日