MD5加密算法
系統(tǒng)
2019-08-12 09:29:27
2009 0
<!--==S 模塊標(biāo)題-->
import java.security.*;
import java.security.spec.*;
class MD5_Test...{
????
????public final static String MD5(String s)...{
????????char hexDigits[] = ...{''0'', ''1'', ''2'', ''3'', ''4'', ''5'', ''6'', ''7'', ''8'', ''9'', ''a'', ''b'', ''c'', ''d'',''e'', ''f''};
????????try
????????...{
????????????byte[] strTemp = s.getBytes();
????????????MessageDigest mdTemp = MessageDigest.getInstance("MD5");
????????????mdTemp.update(strTemp);
????????????byte[] md = mdTemp.digest();
????????????int j = md.length;
????????????char str[] = new char[j * 2];
????????????int k = 0;
????????????for (int i = 0; i < j; i++)
????????????...{
????????????????byte byte0 = md
;
????????????????str[k++] = hexDigits[byte0 >>>4 & 0xf];
????????????????str[k++] = hexDigits[byte0 & 0xf];
????????????}
????????????return new String(str);
????????}
????????catch (Exception e)
????????...{
????????????return null;
????????}
????}
}
主程序如下:
public class md5_main ...{
????public static void main (String[] args)
????...{
????????//MD5_Test aa = new MD5_Test("password");
????????String string= MD5_Test.MD5("password");
????????System.out.println(MD5_Test.MD5("password"));
????????System.out.println(string.equals("5f4dcc3b5aa765d61d8327deb882cf99"));
????}
}
MD5加密算法
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】 元
喜歡作者
JAVA面試題解惑系列(二)——到底創(chuàng)建了幾個St 從Hadoop框架與MapReduce模式中談海量數(shù)據(jù)處理