java实现MD5加密.docpublic class MDSUtil {
private -tatlc final String j5^MZ^S77^”0123456789ABCDEF”; private static final Integer SALT LENGTH = 12;
*将16进制字符串转换成字节数组
gparam hex
6return
public static byte[]
hexStringToByt^(String hex)
lilt len = (() / 2);
byte[] result = new byte[len];
char[] hexChars = ();
for (int i = 0; i < len; i++) {
int pos = i * 2;
result [i] = (byte) {HEX_NUMS_STR. indexOf (hexChars [pos]) «
I \dexQt (hexChars [pos + 1])); }
return result;
*将拆定byte数组转换成16进制宁符串
gp&ram b
***@return
public static String byteToHexString(byte[] b) { StringBuffer hexString = new StringBuffer(); for (int i = 0; i < ; i++) {
String hex = Integer. toHexString& OxFF); if (() == 1) {
hex = 101 + hex;
} (());
}
ratum hexString. toString ();
/ ★
*验证11令是否合法
* ***@param password
gp&ran passwordlnDb
6return
gthrows NoSuchAlgorithmException
6throws UnsupportedEncodingException
*/
public static boolean validPasswcrd(String password, String passwordlnDb)
throws NoSuchAlgorithmException/
UnsupportedEncodingException {
/ /将16进制字符串格式11令转换成字节数组
byte[] pwdlnDb = (passwordlnDb);
//声明盐变萤
byte [ ] salt = new byte [ SALT_LENGTH};
//将盐从数据库中保存的【I令字节数组屮提取出來
System. arraycopyipvjdlnDb, 0z salt, 0r SALT_LENGTH];
//创建消息摘要对彖
MessageDigest md = MessageDigest. getlnstance^^S^};
//将盐数据传入消息摘耍对彖
java实现MD5加密 来自淘豆网www.taodocs.com转载请标明出处.