這是乙個個人認為非常好用的使用md5+salt加密的工具類,一部分**由網上搜尋而得,一部分自己修改新增之後而得。使用這個工具類,非常簡單,從前台拿到密碼passwd,直接hexutil.getencryptedpwd(passwd)就可以返回乙個長度為56的字串,可以用來儲存到
資料庫中,相反,登入的時候,因為md5加密是不可逆的運算,只能拿使用者輸入的密碼走一遍md5+salt加密之後,跟資料庫中的passwd比較,看是否一致,一致時密碼相同,登入成功,通過呼叫hexutil.validpasswd(string passwd,string dbpasswd)方法,就可以了,不用再做其他事。
/**
* md5加密解密及字串對比工具類
*/
public class hexutil
return result;
} /**
* 將陣列轉換成16進製制字串
* * @return string
* @author jacob
* * */
public static string bytetohexstring(byte salt)
} return hexstring.tostring();
} /**
* 密碼驗證
* @param passwd 使用者輸入密碼
* @param dbpasswd 資料庫儲存的密碼
* @return
* @throws nosuchalgorithmexception
* @throws unsupportedencodingexception
*/
public static boolean validpasswd(string passwd, string dbpasswd)
throws nosuchalgorithmexception, unsupportedencodingexceptionelse
} /**
* 獲得md5之後的16進製制字元
* @param passwd 使用者輸入密碼字元
* @return string md5加密後密碼字元
* @throws nosuchalgorithmexception
* @throws unsupportedencodingexception
*/
public static string getencryptedpwd(string passwd)
throws nosuchalgorithmexception, unsupportedencodingexception
}
MD5加密工具類
md5資訊摘要演算法 md5 message digest algorithm 一種被廣泛使用的密碼雜湊函式,可以產生出乙個128位 16位元組 的雜湊值 hash value 用於確保資訊傳輸完整一致。md5由美國密碼學家羅納德 李維斯特 ronald linn rivest 設計,於1992年公...
MD5加密工具
問題引出 md5演算法加密使用者專案操作中我們對一些敏感資訊進行加密,需要注意的是,md5加密是不可逆的。工具類 寫乙個md5演算法,執行結果與mysql的md5 函式相同 將明文密碼轉成md5密碼 123456 e10adc3949ba59abbe56e057f20f883e public cla...
工具 MD5加密
md5 tanajiya.tar.gz 0ca175b9c0f726a831d895e269332461 這就是tanajiya.tar.gz檔案的數字簽名。md5將整個檔案當作乙個大文字資訊,通過其不可逆的字串變換演算法,產生了這個唯一的md5資訊摘要。為了讓讀者朋友對md5的應用有個直觀的認識,...