WEB开发网:源码/*** 类名: MD5Digest<br>* 说明: 用来进行密码加密的md5公用参数<br>* 编写日期: 2001/03/05<br>* 修改者: <
赞助商链接
中资源
>> 最新文章
>> 赞助商
>> 热门文章
WEB开发网文章阅读

在JSP中如何实现MD5加密

作者:未知 文章来源:WEB开发者 更新时间:2008-2-29 14:20:59

源码

/**
 * 类名:      MD5Digest<br>
 * 说明:   用来进行密码加密的md5公用参数<br>
 * 编写日期:  2001/03/05<br>
 * 修改者:    <br>
 * 修改信息:  <br>
 * @author     edgarlo edgarlo@china.com
 * @version    1.0<br>
 */
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Digest
{

    private MessageDigest __md5 = null;
    private StringBuffer __digestBuffer = null;

    public MD5Digest()
        throws NoSuchAlgorithmException
    {
        __md5 = MessageDigest.getInstance("MD5");
        __digestBuffer = new StringBuffer();
    }

    public String md5crypt(String s)
    {
        __digestBuffer.setLength(0);
        byte abyte0[] = __md5.digest(s.getBytes());
        for(int i = 0; i < abyte0.length; i++)
            __digestBuffer.append(toHex(abyte0[i]));

        return __digestBuffer.toString();
    }
    public String toHex(byte one){
   String HEX="0123456789ABCDEF";
   char[] result=new char[2];
   result[0]=HEX.charAt((one & 0xf0) >> 4);
   result[1]=HEX.charAt(one & 0x0f);
   String mm=new String(result);
   return mm;
  }
}

 

 

 

--------------------------------------------------------------------------------
/************************************************
MD5 算法的Java Bean
@author:Topcat Tuppin
Last Modified:10,Mar,2001
*************************************************/
package beartool;
import java.lang.reflect.*;
/*************************************************
md5 类实现了RSA Data Security, Inc.在提交给IETF
的RFC1321中的MD5 message-digest 算法。
*************************************************/

public class MD5 {
/* 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的,
这里把它们实现成为static final是表示了只读,切能在同一个进程空间内的多个
Instance间共享*/
        static final int S11 = 7;
        static final int S12 = 12;
        static final int S13 = 17;
        static final int S14 = 22;

        static final int S21 = 5;
        static final int S22 = 9;
        static final int S23 = 14;
        static final int S24 = 20;

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]  下一页

百度搜索中共有相关主题
[阅读:次] [返回上一页] [打 印]
  • 相关文章
  • 本类热门