php md5 16字符二進制格式 用JAVA寫
問題描述
md5($password_hash, true)這個php函數誰能用java寫出來
問題解答
回答1:import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; class CreateMD5 {public static String getMd5(String plainText , boolean rawOutPut) { try { MessageDigest md = MessageDigest.getInstance('MD5'); md.update(plainText.getBytes()); byte b[] = md.digest();int i;StringBuffer buf = new StringBuffer(''); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append('0'); buf.append(Integer.toHexString(i)); } if(rawOutPut){return buf.toString().substring(8, 24); } return buf.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; }} public static void main(String[] args) { System.out.println(CreateMD5.getMd5('segmentfault',true)); } }
相關文章:
1. html - 移動端radio無法選中2. apache - 怎么給localhost后面默認加上8080端口3. html5 - datatables 加載不出來數據。4. mysql - 數據庫JOIN查詢5. 我設置的背景怎么顯示不出來6. 關于Navicat連接到mysql,我改了root的密碼后,Navicat連接報錯1862?7. php7.3.4中怎么開啟pdo驅動8. python - 用scrapy-splash爬取網站 為啥iframe下的內容沒有被返回9. mysql - 數據庫建字段,默認值空和empty string有什么區別 11010. windows-7 - Win7中Vmware Workstatoin與Xampp中Apache服務器端口沖突?
