java md5工具類分享
更新時間:2014年02月17日 11:58:02 作者:
這篇文章主要介紹了java的md5工具類,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
import javasecurityMessageDigest;
import javasecurityNoSuchAlgorithmException;
/**
* MD5工具類
*
* @author
* @version 0
*/
public class Md5Util {
/**
* Md
*
* @param value the value
* @return the string
*/
public static String md5(String value) {
try {
MessageDigest md = MessageDigestgetInstance("md5");
byte[] e = mddigest(valuegetBytes());
return toHex(e);
}
catch (NoSuchAlgorithmException e) {
eprintStackTrace();
return value;
}
}
/**
* Md
*
* @param bytes the bytes
* @return the string
*/
public static String md5(byte[] bytes){
try {
MessageDigest md = MessageDigestgetInstance("md5");
byte[] e = mddigest(bytes);
return toHex(e);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
/**
* To hex
*
* @param bytes the bytes
* @return the string
*/
private static String toHex(byte bytes[]){
StringBuilder hs = new StringBuilder();
String stmp ="";
for (int n = 0; n < byteslength; n++) {
stmp = IntegertoHexString(bytes[n] & 0xff);
if (stmplength() == 1)
hsappend("0")append(stmp);
else
hsappend(stmp);
}
return hstoString();
}
}
相關(guān)文章
spring boot 2.x html中引用css和js失效問題及解決方法
這篇文章主要介紹了spring boot 2.x html中引用css和js失效,需要的朋友可以參考下2018-11-11MyBatis在insert插入操作時返回主鍵ID的配置(推薦)
這篇文章主要介紹了MyBatis在insert插入操作時返回主鍵ID的配置的相關(guān)資料,需要的朋友可以參考下2017-10-10基于CyclicBarrier和CountDownLatch的使用區(qū)別說明
這篇文章主要介紹了基于CyclicBarrier和CountDownLatch的使用區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09SpringBoot整合SpringSecurity實現(xiàn)權(quán)限控制之實現(xiàn)多標(biāo)簽頁
這篇文章主要介紹了SpringBoot整合SpringSecurity實現(xiàn)權(quán)限控制之實現(xiàn)多標(biāo)簽頁,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-11-11JAVA實現(xiàn)網(wǎng)絡(luò)/本地圖片轉(zhuǎn)BASE64存儲代碼示例
這篇文章主要給大家介紹了關(guān)于JAVA實現(xiàn)網(wǎng)絡(luò)/本地圖片轉(zhuǎn)BASE64存儲的相關(guān)資料,Base64是網(wǎng)絡(luò)上最常見的用于傳輸8Bit字節(jié)碼的編碼方式之一,Base64就是一種基于64個可打印字符來表示二進制數(shù)據(jù)的方法,需要的朋友可以參考下2023-07-07SpringBoot工程啟動順序與自定義監(jiān)聽超詳細講解
這篇文章主要介紹了SpringBoot工程啟動順序與自定義監(jiān)聽,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-11-11