类名: MD5Digest
* 说明: 用来进行密码加密的md5公用参数
* 编写日期: 2001/03/05
* 修改者:
* 修改信息:
* @author edgarlo edgarlo@china.com * @version 1.0
*/ 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; |