码迷,mamicode.com
首页 > 编程语言 > 详细

<<< Java生成Md5

时间:2014-06-12 11:11:00      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   java   http   ext   

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cn.sevennight.test;
 
import java.security.MessageDigest;
 
public class md5{
 
    public static String MD5(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.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));
            }
            return new String(buf.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
        public static void main(String[] args) {
        String md5 =MD5("123456");
        System.out.println(md5);
    }
}

  bubuko.com,布布扣

bubuko.com,布布扣

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<<< Java生成Md5,布布扣,bubuko.com

<<< Java生成Md5

标签:class   blog   code   java   http   ext   

原文地址:http://www.cnblogs.com/7night/p/3782380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!