java 對字符串生成md5

原生的md5 生成太麻煩了,所以還是安心用工具吧

方法:

import org.springframework.util.DigestUtils;  //spring框架

DigestUtils.md5DigestAsHex( strValue .getBytes());

由於該方法屬於spring  util 下的工具包

所以要導入 spring-core 包

 

 

 

加鹽:對原字符串加入固定的字符串,使之組成新串

原:abc

加:123  (用戶並不知道我們加如了什麼內容)

新串:abc123

abc123--> md5 於abc -->md5 完全沒有關係

 

String password="123";

password+="yan";

password = DigestUtils.md5DigestAsHex( password.getBytes());

此時別人,即使拿到數據的加密數據,也沒有用,無法轉換爲從前的真正串

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章