php md5 16字符二進(jìn)制格式 用JAVA寫
問題描述
md5($password_hash, true)這個(gè)php函數(shù)誰能用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)); } }
相關(guān)文章:
1. phpstudy8.1沒集成mysql-front2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法4. docker鏡像push報(bào)錯(cuò)5. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題6. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。7. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?8. javascript - QQ第三方登錄的問題9. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!10. html5 - datatables 加載不出來數(shù)據(jù)。

網(wǎng)公網(wǎng)安備