信息发布软件,b2b软件,广告发布软件

 找回密码
 立即注册
搜索
查看: 3578|回复: 13
打印 上一主题 下一主题

[『JSP图文教程』] 用JSP如何实现自己的MD5给自己的东东加层密文

[复制链接]

1868

主题

1878

帖子

1万

积分

积分
10928
跳转到指定楼层
宣传软件楼主
发表于 2017-7-3 21:46:15 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

软件教程首图:

软件教程分类:JSP 图文教程 

软件图文教程视频教程分类:软件图文教程 

软件教程难易程度:软件初级教程 

软件教程发布日期:2017-07-03

软件教程关键字:用JSP如何实现自己的MD5给自己的东东加层密文

① 本信息收集于网络,如有不对的地方欢迎联系我纠正!
② 本信息免费收录,不存在价格的问题!
③ 如果您的网站也想这样出现在这里,请您加好友情链接,我当天会审核通过!

④友情链接关键字:软件定制网站 网址:http://www.postbbs.com

软件教程详细描述
本帖最后由 群发软件 于 2017-7-3 22:01 编辑

/**

建立一个名为MD5Digest的java文件,内容如下

/**
* 类名:      MD5Digest<br>
* 说明:   用来进行密码加密的md5公用参数<br>
* 编写日期:  2011/03/05<br>
* 修改者:    <br>
* 修改信息:  <br>
*/

在各种应用系统的开发中,经常需要存储用户信息,很多地方都要存储用户密码,而将用户密码直接存储在服务器上显然是不安全的,本文简要介绍在JSP中如何实现MD5加密的方法,希望能抛砖引玉。
(一)消息摘要简介
一个消息摘要就是一个数据块的数字指纹。即对一个任意长度的一个数据块进行计算,产生一个唯一指印(对于SHA1是产生一个20字节的二进制数组)。消息摘要是一种与消息认证码结合使用以确保消息完整性的技术。主要使用单向散列函数算法,可用于检验消息的完整性,和通过散列密码直接以文本形式保存等,目前广泛使用的算法有MD4、MD5、SHA-1。
消息摘要有两个基本属性:
两个不同的报文难以生成相同的摘要
难以对指定的摘要生成一个报文,而可以由该报文反推算出该指定的摘要。
Java源码
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)); 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;   static final int S31 = 4;   static final int S32 = 11;   static final int S33 = 16;   static final int S34 = 23;   static final int S41 = 6;   static final int S42 = 10;   static final int S43 = 15;   static final int S44 = 21;   static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };   /* 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中   被定义到MD5_CTX结构中    */   private long[] state = new long[4];// state (ABCD)   private long[] count = new long[2];// number of bits, modulo 2^64 (lsb first)   private byte[] buffer = new byte[64]; // input buffer    /* digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的     16进制ASCII表示.   */   public String digestHexStr;    /* digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.   */   private byte[] digest = new byte[16];    /*   getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串   返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.   */   public String getMD5ofStr(String inbuf) {   md5Init();   md5Update(inbuf.getBytes(), inbuf.length());   md5Final();   digestHexStr = "";   for (int i = 0; i < 16; i++) {   digestHexStr += byteHEX(digest);   }   return digestHexStr;   }   // 这是MD5这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数   public MD5() {   md5Init();   return;   }   /* md5Init是一个初始化函数,初始化核心变量,装入标准的幻数 */   private void md5Init() {   count[0] = 0L;   count[1] = 0L;   ///* Load magic initialization constants.   state[0] = 0x67452301L;   state[1] = 0xefcdab89L;   state[2] = 0x98badcfeL;   state[3] = 0x10325476L;   return;   }   /* F, G, H ,I 是4个基本的MD5函数,在原始的MD5的C实现中,由于它们是   简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们     实现成了private方法,名字保持了原来C中的。 */   private long F(long x, long y, long z) {   return (x & y) | ((~x) & z);   }   private long G(long x, long y, long z) {   return (x & z) | (y & (~z));   }   private long H(long x, long y, long z) {   return x ^ y ^ z;   }   private long I(long x, long y, long z) {   return y ^ (x | (~z));   }    /*   FF,GG,HH和II将调用F,G,H,I进行近一步变换   FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.   Rotation is separate from addition to prevent recomputation.   */   private long FF(long a, long b, long c, long d, long x, long s,   long ac) {   a += F (b, c, d) + x + ac;   a = ((int) a << s) | ((int) a >>> (32 - s));   a += b;   return a;   }   private long GG(long a, long b, long c, long d, long x, long s,   long ac) {   a += G (b, c, d) + x + ac;   a = ((int) a << s) | ((int) a >>> (32 - s));   a += b;   return a;   }   private long HH(long a, long b, long c, long d, long x, long s,   long ac) {   a += H (b, c, d) + x + ac;   a = ((int) a << s) | ((int) a >>> (32 - s));   a += b;   return a;   }   private long II(long a, long b, long c, long d, long x, long s,   long ac) {   a += I (b, c, d) + x + ac;   a = ((int) a << s) | ((int) a >>> (32 - s));   a += b;   return a;   }   /*   md5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个   函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private的   */   private void md5Update(byte[] inbuf, int inputLen) {   int i, index, partLen;   byte[] block = new byte[64];   index = (int)(count[0] >>> 3) & 0x3F;   // /* Update number of bits */   if ((count[0] += (inputLen << 3)) < (inputLen << 3))   count[1]++;   count[1] += (inputLen >>> 29);   partLen = 64 - index;   // Transform as many times as possible.   if (inputLen >= partLen) {   md5Memcpy(buffer, inbuf, index, 0, partLen);   md5Transform(buffer);   for (i = partLen; i + 63 < inputLen; i += 64) {   md5Memcpy(block, inbuf, 0, i, 64);   md5Transform (block);   }   index = 0;   } else   i = 0;   ///* Buffer remaining input */   md5Memcpy(buffer, inbuf, index, i, inputLen - i);   }    /*   md5Final整理和填写输出结果   */   private void md5Final () {   byte[] bits = new byte[8];   int index, padLen;   ///* Save number of bits */   Encode (bits, count, 8);   ///* Pad out to 56 mod 64.   index = (int)(count[0] >>> 3) & 0x3f;   padLen = (index < 56) ? (56 - index) : (120 - index);   md5Update (PADDING, padLen);   ///* Append length (before padding) */   md5Update(bits, 8);   ///* Store state in digest */   Encode (digest, state, 16);   }    /* md5Memcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的         字节拷贝到output的outpos位置开始   */   private void md5Memcpy (byte[] output, byte[] input,   int outpos, int inpos, int len)   {   int i;   for (i = 0; i < len; i++)   output[outpos + i] = input[inpos + i];   }    /*   md5Transform是MD5核心变换程序,有md5Update调用,block是分块的原始字节   */   private void md5Transform (byte block[]) {   long a = state[0], b = state[1], c = state[2], d = state[3];   long[] x = new long[16];   Decode (x, block, 64);   /* Round 1 */   a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */   d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */   c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */   b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */   a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */   d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */   c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */   b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */   a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */   d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */   c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */   b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */   a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */   d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */   c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */   b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */   /* Round 2 */   a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */   d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */   c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */   b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */   a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */   d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */   c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */   b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */   a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */   d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */   c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */   b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */   a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */   d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */   c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */   b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */   /* Round 3 */   a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */   d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */   c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */   b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */   a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */   d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */   c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */   b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */   a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */   d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */   c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */   b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */   a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */   d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */   c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */   b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */   /* Round 4 */   a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */   d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */   c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */   b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */   a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */   d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */   c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */   b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */   a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */   d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */   c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */   b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */   a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */   d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */   c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */   b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */   state[0] += a;   state[1] += b;   state[2] += c;   state[3] += d;   }    /*Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,   只拆低32bit,以适应原始C实现的用途   */   private void Encode (byte[] output, long[] input, int len) {   int i, j;   for (i = 0, j = 0; j < len; i++, j += 4) {   output[j] = (byte)(input & 0xffL);   output[j + 1] = (byte)((input >>> 8) & 0xffL);   output[j + 2] = (byte)((input >>> 16) & 0xffL);   output[j + 3] = (byte)((input >>> 24) & 0xffL);   }   }   /*Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,   只合成低32bit,高32bit清零,以适应原始C实现的用途   */   private void Decode (long[] output, byte[] input, int len) {   int i, j;    for (i = 0, j = 0; j < len; i++, j += 4)   output = b2iu(input[j]) |   (b2iu(input[j + 1]) << 8) |   (b2iu(input[j + 2]) << 16) |   (b2iu(input[j + 3]) << 24);   return;   }    /*   b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算   */   public static long b2iu(byte b) {   return b < 0 ? b & 0x7F + 128 : b;   }    /*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,    因为java中的byte的toString无法实现这一点,我们又没有C语言中的   sprintf(outbuf,"%02X",ib)   */   public static String byteHEX(byte ib) {   char[] Digit = { '0','1','2','3','4','5','6','7','8','9',   'A','B','C','D','E','F' };   char [] ob = new char[2];   ob[0] = Digit[(ib >>> 4) & 0X0F];   ob[1] = Digit[ib & 0X0F];   String s = new String(ob);   return s;   }   public static void main(String args[]) {    MD5 m = new MD5();   if (Array.getLength(args) == 0) {//如果没有参数,执行标准的Test Suite    System.out.println("MD5 Test suite:");   System.out.println("MD5(\"\"):"+m.getMD5ofStr(""));   System.out.println("MD5(\"a\"):"+m.getMD5ofStr("a"));   System.out.println("MD5(\"abc\"):"+m.getMD5ofStr("abc"));   System.out.println("MD5(\"message digest\"):"+m.getMD5ofStr("message digest"));   System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"+   m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));   System.out.println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"+   m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));   }   else    System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));     }   }
JSP中的使用方法
-------------------------------------------------------------------------------
<%@ page language='java' %> <jsp:useBean id='oMD5' scope='request' class='beartool.MD5'/> <%@ page import='java.util.*'%> <%@ page import='java.sql.*'%> <html> <body> <% String userid = request.getParameter("UserID");//获取用户输入UserID String password = request.getParameter("assword"); //获取用户输入的Password  String pwdmd5 = oMD5.getMD5ofStr(password);//计算MD5的值  PrintWriter rp = response.getWriter();  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  Connection con = DriverManager.getConnection("jdbcdbc:community", "", ""); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from users where userID ='"+userid+"' and pwdmd5= '" + pwdmd5+"'" ); if (rs.next())  { rp.print("Login OK");  } else { rp.print("Login Fail"); } stmt.close(); con.close();  %> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

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));

        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文件,内容如下

/************************************************
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;

        static final int S31 = 4;
        static final int S32 = 11;
        static final int S33 = 16;
        static final int S34 = 23;

        static final int S41 = 6;
        static final int S42 = 10;
        static final int S43 = 15;
        static final int S44 = 21;

        static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        /* 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中
           被定义到MD5_CTX结构中
        
         */
        private long[] state = new long[4];  // state (ABCD)
        private long[] count = new long[2];  // number of bits, modulo 2^64 (lsb first)
        private byte[] buffer = new byte[64]; // input buffer
        
/* digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的
  16进制ASCII表示.
*/
        public String digestHexStr;
        
        /* digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.
*/
        private byte[] digest = new byte[16];
        
/*
getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串
返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
*/
        public String getMD5ofStr(String inbuf) {
                md5Init();
                md5Update(inbuf.getBytes(), inbuf.length());
                md5Final();
                digestHexStr = "";
                for (int i = 0; i < 16; i++) {
                        digestHexStr += byteHEX(digest);
                }
                return digestHexStr;

        }
        // 这是MD5这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
        public MD5() {
                md5Init();

                return;
        }
      


        /* md5Init是一个初始化函数,初始化核心变量,装入标准的幻数 */
        private void md5Init() {
                count[0] = 0L;
                count[1] = 0L;
                ///* Load magic initialization constants.

                state[0] = 0x67452301L;
                state[1] = 0xefcdab89L;
                state[2] = 0x98badcfeL;
                state[3] = 0x10325476L;

                return;
        }
        /* F, G, H ,I 是4个基本的MD5函数,在原始的MD5的C实现中,由于它们是
        简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们
       实现成了private方法,名字保持了原来C中的。 */

        private long F(long x, long y, long z) {
                return (x & y) | ((~x) & z);

        }
        private long G(long x, long y, long z) {
                return (x & z) | (y & (~z));

        }
        private long H(long x, long y, long z) {
                return x ^ y ^ z;
        }

        private long I(long x, long y, long z) {
                return y ^ (x | (~z));
        }
        
       /*
          FF,GG,HH和II将调用F,G,H,I进行近一步变换
          FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
          Rotation is separate from addition to prevent recomputation.
       */

        private long FF(long a, long b, long c, long d, long x, long s,
                long ac) {
                a += F (b, c, d) + x + ac;
                a = ((int) a << s) | ((int) a >>> (32 - s));
                a += b;
                return a;
        }

        private long GG(long a, long b, long c, long d, long x, long s,
                long ac) {
                a += G (b, c, d) + x + ac;
                a = ((int) a << s) | ((int) a >>> (32 - s));
                a += b;
                return a;
        }
        private long HH(long a, long b, long c, long d, long x, long s,
                long ac) {
                a += H (b, c, d) + x + ac;
                a = ((int) a << s) | ((int) a >>> (32 - s));
                a += b;
                return a;
        }
        private long II(long a, long b, long c, long d, long x, long s,
                long ac) {
                a += I (b, c, d) + x + ac;
                a = ((int) a << s) | ((int) a >>> (32 - s));
                a += b;
                return a;
        }
        /*
         md5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个
         函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private的
        */
        private void md5Update(byte[] inbuf, int inputLen) {

                int i, index, partLen;
                byte[] block = new byte[64];
                index = (int)(count[0] >>> 3) & 0x3F;
                // /* Update number of bits */
                if ((count[0] += (inputLen << 3)) < (inputLen << 3))
                        count[1]++;
                count[1] += (inputLen >>> 29);

                partLen = 64 - index;

                // Transform as many times as possible.
                if (inputLen >= partLen) {
                        md5Memcpy(buffer, inbuf, index, 0, partLen);
                        md5Transform(buffer);

                        for (i = partLen; i + 63 < inputLen; i += 64) {

                                md5Memcpy(block, inbuf, 0, i, 64);
                                md5Transform (block);
                        }
                        index = 0;

                } else

                        i = 0;

                ///* Buffer remaining input */
                md5Memcpy(buffer, inbuf, index, i, inputLen - i);

        }
        
        /*
          md5Final整理和填写输出结果
        */
        private void md5Final () {
                byte[] bits = new byte[8];
                int index, padLen;

                ///* Save number of bits */
                Encode (bits, count, 8);

                ///* Pad out to 56 mod 64.
                index = (int)(count[0] >>> 3) & 0x3f;
                padLen = (index < 56) ? (56 - index) : (120 - index);
                md5Update (PADDING, padLen);

                ///* Append length (before padding) */
                md5Update(bits, 8);

                ///* Store state in digest */
                Encode (digest, state, 16);

        }
         
        /* md5Memcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的
      字节拷贝到output的outpos位置开始
        */

        private void md5Memcpy (byte[] output, byte[] input,
                int outpos, int inpos, int len)
        {
                int i;

                for (i = 0; i < len; i++)
                        output[outpos + i] = input[inpos + i];
        }
        
        /*
           md5Transform是MD5核心变换程序,有md5Update调用,block是分块的原始字节
        */
        private void md5Transform (byte block[]) {
                long a = state[0], b = state[1], c = state[2], d = state[3];
                long[] x = new long[16];

                Decode (x, block, 64);

                /* Round 1 */
                a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
                d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
                c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
                b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
                a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
                d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
                c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
                b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
                a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
                d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
                c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
                b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
                a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
                d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
                c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
                b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */

                /* Round 2 */
                a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
                d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
                c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
                b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
                a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
                d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
                c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
                b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
                a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
                d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
                c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
                b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
                a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
                d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
                c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
                b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */

                /* Round 3 */
                a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
                d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
                c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
                b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
                a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
                d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
                c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
                b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
                a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
                d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
                c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
                b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
                a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
                d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
                c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
                b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */

                /* Round 4 */
                a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
                d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
                c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
                b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
                a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
                d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
                c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
                b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
                a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
                d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
                c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
                b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
                a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
                d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
                c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
                b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */

                state[0] += a;
                state[1] += b;
                state[2] += c;
                state[3] += d;

        }
        
        /*Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,
          只拆低32bit,以适应原始C实现的用途
        */
        private void Encode (byte[] output, long[] input, int len) {
                int i, j;

                for (i = 0, j = 0; j < len; i++, j += 4) {
                        output[j] = (byte)(input & 0xffL);
                        output[j + 1] = (byte)((input >>> 8) & 0xffL);
                        output[j + 2] = (byte)((input >>> 16) & 0xffL);
                        output[j + 3] = (byte)((input >>> 24) & 0xffL);
                }
        }

        /*Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
          只合成低32bit,高32bit清零,以适应原始C实现的用途
        */
        private void Decode (long[] output, byte[] input, int len) {
                int i, j;


                for (i = 0, j = 0; j < len; i++, j += 4)
                        output = b2iu(input[j]) |
                                (b2iu(input[j + 1]) << 8) |
                                (b2iu(input[j + 2]) << 16) |
                                (b2iu(input[j + 3]) << 24);

                return;
        }
      
        /*
          b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
        */
        public static long b2iu(byte b) {
                return b < 0 ? b & 0x7F + 128 : b;
        }
        
/*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
 因为java中的byte的toString无法实现这一点,我们又没有C语言中的
sprintf(outbuf,"%02X",ib)
*/
        public static String byteHEX(byte ib) {
                char[] Digit = { '0','1','2','3','4','5','6','7','8','9',
                'A','B','C','D','E','F' };
                char [] ob = new char[2];
                ob[0] = Digit[(ib >>> 4) & 0X0F];
                ob[1] = Digit[ib & 0X0F];
                String s = new String(ob);
                return s;
        }

        public static void main(String args[]) {


                MD5 m = new MD5();
                if (Array.getLength(args) == 0) {   //如果没有参数,执行标准的Test Suite
               
                        System.out.println("MD5 Test suite:");
                System.out.println("MD5(\"\"):"+m.getMD5ofStr(""));
                System.out.println("MD5(\"a\"):"+m.getMD5ofStr("a"));
                System.out.println("MD5(\"abc\"):"+m.getMD5ofStr("abc"));
                System.out.println("MD5(\"message digest\"):"+m.getMD5ofStr("message digest"));
                System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"+
                        m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));
                System.out.println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"+
                      m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
                }
                else
                      System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));
               
         
        }

}


三、将这两个文件都进行编译,编译后保存在:\WEB-INF\classes\beartool

四、到JSP页面中测试,代码如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%request.setCharacterEncoding("gb2312");%>
<jsp:useBean id='oMD5' scope='request' class='beartool.MD5'/>
    <%
     String password="abc123";
   String pwdmd5 = oMD5.getMD5ofStr(password);
  out.println(pwdmd5);
    %>

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

  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;

  static final int S31 = 4;
  static final int S32 = 11;
  static final int S33 = 16;
  static final int S34 = 23;

  static final int S41 = 6;
  static final int S42 = 10;
  static final int S43 = 15;
  static final int S44 = 21;

  static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  /* 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中
  被定义到MD5_CTX结构中
  
  */
  private long[] state = new long[4];// state (ABCD)
  private long[] count = new long[2];// number of bits, modulo 2^64 (lsb first)
  private byte[] buffer = new byte[64]; // input buffer
  
  /* digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的
    16进制ASCII表示.
  */
  public String digestHexStr;
  
  /* digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.
  */
  private byte[] digest = new byte[16];
  
  /*
  getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串
  返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
  */
  public String getMD5ofStr(String inbuf) {
  md5Init();
  md5Update(inbuf.getBytes(), inbuf.length());
  md5Final();
  digestHexStr = "";
  for (int i = 0; i < 16; i++) {
  digestHexStr += byteHEX(digest);
  }
  return digestHexStr;

  }
  // 这是MD5这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
  public MD5() {
  md5Init();

  return;
  }
  /* md5Init是一个初始化函数,初始化核心变量,装入标准的幻数 */
  private void md5Init() {
  count[0] = 0L;
  count[1] = 0L;
  ///* Load magic initialization constants.

  state[0] = 0x67452301L;
  state[1] = 0xefcdab89L;
  state[2] = 0x98badcfeL;
  state[3] = 0x10325476L;

  return;
  }
  /* F, G, H ,I 是4个基本的MD5函数,在原始的MD5的C实现中,由于它们是
  简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们
    实现成了private方法,名字保持了原来C中的。 */

  private long F(long x, long y, long z) {
  return (x & y) | ((~x) & z);

  }
  private long G(long x, long y, long z) {
  return (x & z) | (y & (~z));

  }
  private long H(long x, long y, long z) {
  return x ^ y ^ z;
  }

  private long I(long x, long y, long z) {
  return y ^ (x | (~z));
  }
  
  /*
  FF,GG,HH和II将调用F,G,H,I进行近一步变换
  FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
  Rotation is separate from addition to prevent recomputation.
  */

  private long FF(long a, long b, long c, long d, long x, long s,
  long ac) {
  a += F (b, c, d) + x + ac;
  a = ((int) a << s) | ((int) a >>> (32 - s));
  a += b;
  return a;
  }

  private long GG(long a, long b, long c, long d, long x, long s,
  long ac) {
  a += G (b, c, d) + x + ac;
  a = ((int) a << s) | ((int) a >>> (32 - s));
  a += b;
  return a;
  }
  private long HH(long a, long b, long c, long d, long x, long s,
  long ac) {
  a += H (b, c, d) + x + ac;
  a = ((int) a << s) | ((int) a >>> (32 - s));
  a += b;
  return a;
  }
  private long II(long a, long b, long c, long d, long x, long s,
  long ac) {
  a += I (b, c, d) + x + ac;
  a = ((int) a << s) | ((int) a >>> (32 - s));
  a += b;
  return a;
  }
  /*
  md5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个
  函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private的
  */
  private void md5Update(byte[] inbuf, int inputLen) {

  int i, index, partLen;
  byte[] block = new byte[64];
  index = (int)(count[0] >>> 3) & 0x3F;
  // /* Update number of bits */
  if ((count[0] += (inputLen << 3)) < (inputLen << 3))
  count[1]++;
  count[1] += (inputLen >>> 29);

  partLen = 64 - index;

  // Transform as many times as possible.
  if (inputLen >= partLen) {
  md5Memcpy(buffer, inbuf, index, 0, partLen);
  md5Transform(buffer);

  for (i = partLen; i + 63 < inputLen; i += 64) {

  md5Memcpy(block, inbuf, 0, i, 64);
  md5Transform (block);
  }
  index = 0;

  } else

  i = 0;

  ///* Buffer remaining input */
  md5Memcpy(buffer, inbuf, index, i, inputLen - i);

  }
  
  /*
  md5Final整理和填写输出结果
  */
  private void md5Final () {
  byte[] bits = new byte[8];
  int index, padLen;

  ///* Save number of bits */
  Encode (bits, count, 8);

  ///* Pad out to 56 mod 64.
  index = (int)(count[0] >>> 3) & 0x3f;
  padLen = (index < 56) ? (56 - index) : (120 - index);
  md5Update (PADDING, padLen);

  ///* Append length (before padding) */
  md5Update(bits, 8);

  ///* Store state in digest */
  Encode (digest, state, 16);

  }
  
  /* md5Memcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的
        字节拷贝到output的outpos位置开始
  */

  private void md5Memcpy (byte[] output, byte[] input,
  int outpos, int inpos, int len)
  {
  int i;

  for (i = 0; i < len; i++)
  output[outpos + i] = input[inpos + i];
  }
  
  /*
  md5Transform是MD5核心变换程序,有md5Update调用,block是分块的原始字节
  */
  private void md5Transform (byte block[]) {
  long a = state[0], b = state[1], c = state[2], d = state[3];
  long[] x = new long[16];

  Decode (x, block, 64);

  /* Round 1 */
  a = FF (a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
  d = FF (d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
  c = FF (c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
  b = FF (b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
  a = FF (a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
  d = FF (d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
  c = FF (c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
  b = FF (b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
  a = FF (a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
  d = FF (d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
  c = FF (c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
  b = FF (b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
  a = FF (a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
  d = FF (d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
  c = FF (c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
  b = FF (b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */

  /* Round 2 */
  a = GG (a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
  d = GG (d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
  c = GG (c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
  b = GG (b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
  a = GG (a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
  d = GG (d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
  c = GG (c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
  b = GG (b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
  a = GG (a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
  d = GG (d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
  c = GG (c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
  b = GG (b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
  a = GG (a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
  d = GG (d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
  c = GG (c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
  b = GG (b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */

  /* Round 3 */
  a = HH (a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
  d = HH (d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
  c = HH (c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
  b = HH (b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
  a = HH (a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
  d = HH (d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
  c = HH (c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
  b = HH (b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
  a = HH (a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
  d = HH (d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
  c = HH (c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
  b = HH (b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
  a = HH (a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
  d = HH (d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
  c = HH (c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
  b = HH (b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */

  /* Round 4 */
  a = II (a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
  d = II (d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
  c = II (c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
  b = II (b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
  a = II (a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
  d = II (d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
  c = II (c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
  b = II (b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
  a = II (a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
  d = II (d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
  c = II (c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
  b = II (b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
  a = II (a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
  d = II (d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
  c = II (c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
  b = II (b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */

  state[0] += a;
  state[1] += b;
  state[2] += c;
  state[3] += d;

  }
  
  /*Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的,
  只拆低32bit,以适应原始C实现的用途
  */
  private void Encode (byte[] output, long[] input, int len) {
  int i, j;

  for (i = 0, j = 0; j < len; i++, j += 4) {
  output[j] = (byte)(input & 0xffL);
  output[j + 1] = (byte)((input >>> 8) & 0xffL);
  output[j + 2] = (byte)((input >>> 16) & 0xffL);
  output[j + 3] = (byte)((input >>> 24) & 0xffL);
  }
  }

  /*Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
  只合成低32bit,高32bit清零,以适应原始C实现的用途
  */
  private void Decode (long[] output, byte[] input, int len) {
  int i, j;

  
  for (i = 0, j = 0; j < len; i++, j += 4)
  output = b2iu(input[j]) |
  (b2iu(input[j + 1]) << 8) |
  (b2iu(input[j + 2]) << 16) |
  (b2iu(input[j + 3]) << 24);

  return;
  }
  
  /*
  b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
  */
  public static long b2iu(byte b) {
  return b < 0 ? b & 0x7F + 128 : b;
  }
  
  /*byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
   因为java中的byte的toString无法实现这一点,我们又没有C语言中的
  sprintf(outbuf,"%02X",ib)
  */
  public static String byteHEX(byte ib) {
  char[] Digit = { '0','1','2','3','4','5','6','7','8','9',
  'A','B','C','D','E','F' };
  char [] ob = new char[2];
  ob[0] = Digit[(ib >>> 4) & 0X0F];
  ob[1] = Digit[ib & 0X0F];
  String s = new String(ob);
  return s;
  }

  public static void main(String args[]) {

  
  MD5 m = new MD5();
  if (Array.getLength(args) == 0) {//如果没有参数,执行标准的Test Suite
  
  System.out.println("MD5 Test suite:");
  System.out.println("MD5(\"\"):"+m.getMD5ofStr(""));
  System.out.println("MD5(\"a\"):"+m.getMD5ofStr("a"));
  System.out.println("MD5(\"abc\"):"+m.getMD5ofStr("abc"));
  System.out.println("MD5(\"message digest\"):"+m.getMD5ofStr("message digest"));
  System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"+
  m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));
  System.out.println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"+
  m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
  }
  else
  System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));
  
  
  }

  }

  JSP中的使用方法

  -------------------------------------------------------------------------------
  <%@ page language='java' %>
  <jsp:useBean id='oMD5' scope='request' class='beartool.MD5'/>

  <%@ page import='java.util.*'%>
  <%@ page import='java.sql.*'%>
  <html>
  <body>
  <%
  String userid = request.getParameter("UserID");//获取用户输入UserID
  String password = request.getParameter("assword"); //获取用户输入的Password
  
  String pwdmd5 = oMD5.getMD5ofStr(password);//计算MD5的值
  
  PrintWriter rp = response.getWriter();
  
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  
  Connection con = DriverManager.getConnection("jdbcdbc:community", "", "");

  Statement stmt = con.createStatement();

  ResultSet rs = stmt.executeQuery("select * from users where userID ='"+userid+"' and pwdmd5= '" + pwdmd5+"'" );

  if (rs.next())
  {
  rp.print("Login OK");
  
  }
  else
  {
  rp.print("Login Fail");
  }

  stmt.close();
  con.close();
  
  %>


unto很实用很暴力的JSP打造自己的收发邮件系统next阿里巴巴自动信息发布软件
回复

使用道具 举报

0

主题

632

帖子

628

积分

积分
628
信息发布软件沙发
发表于 2017-7-7 00:54:51 | 只看该作者
,样子不错,厂家给力

回复 支持 反对

使用道具 举报

0

主题

586

帖子

582

积分

积分
582
推广工具板凳
发表于 2017-7-13 03:49:33 | 只看该作者
意思,出差一直没顾上。微信平台开发找你们做绝对是正确的选择。服务是值得肯定的,售后也非常到位,技术支持很强大,重点是热心.不厌其烦。不像有些玩技术的那个清高啊,那个沟通难度啊真不是一般的高。

回复 支持 反对

使用道具 举报

0

主题

632

帖子

630

积分

积分
630
软件定制开发地板
发表于 2017-7-13 12:04:19 | 只看该作者
然中间有些波折,对设计结果还是比较满意的。好评。

回复 支持 反对

使用道具 举报

0

主题

591

帖子

591

积分

积分
591
5#定制软件#
发表于 2017-7-15 12:59:13 | 只看该作者
,风格很赞,系统很稳定。很好。

回复 支持 反对

使用道具 举报

0

主题

636

帖子

624

积分

积分
624
6#定制软件#
发表于 2017-7-17 15:41:35 | 只看该作者
搞了,雏形出来了,看起来真不错,还有多谢工作人员耐心指导。

回复 支持 反对

使用道具 举报

0

主题

596

帖子

677

积分

积分
677
7#定制软件#
发表于 2017-7-17 17:30:40 | 只看该作者
快,而且都完美解决!

回复 支持 反对

使用道具 举报

0

主题

612

帖子

596

积分

积分
596
8#定制软件#
发表于 2017-7-20 05:47:30 | 只看该作者
服务超好

回复 支持 反对

使用道具 举报

1

主题

2204

帖子

565

积分

积分
565
9#定制软件#
发表于 2017-7-21 23:15:57 | 只看该作者
好,专业的就是不一样,价格很便宜,大公司,给中评是因为对客服的无语

回复 支持 反对

使用道具 举报

0

主题

623

帖子

612

积分

积分
612
10#定制软件#
发表于 2017-7-24 04:21:06 | 只看该作者
服务也好。谢谢卖家帮我解决。

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关导读
信息发布软件AIWROK软件滑动方法集合示例
AIWROK软件滑动方法集合示例
信息发布软件AIWROK软件安卓AIWROK汇集软件点击
AIWROK软件安卓AIWROK汇集软件点击
信息发布软件苹果系统点击方法综合示例
苹果系统点击方法综合示例
信息发布软件AIWROK苹果系统找图方法完整示例集合
AIWROK苹果系统找图方法完整示例集合
信息发布软件苹果系统找图方法完整示例集合
苹果系统找图方法完整示例集合
信息发布软件苹果IOS系统找字OCR方法例子
苹果IOS系统找字OCR方法例子
信息发布软件AIWORK软件数组高级示例
AIWORK软件数组高级示例
信息发布软件AIWROK软件运算符封装库示例
AIWROK软件运算符封装库示例
信息发布软件AIWROK软件语法运行小示例
AIWROK软件语法运行小示例
信息发布软件AIWROK软件JS循环小示例
AIWROK软件JS循环小示例
信息发布软件AIWROK软件H5网页被主脚本获取值用法
AIWROK软件H5网页被主脚本获取值用法
信息发布软件AIWROK软件创建可暂停恢复的多线程任务
AIWROK软件创建可暂停恢复的多线程任务
信息发布软件AIWROK软件类型转换方法例子
AIWROK软件类型转换方法例子
信息发布软件AIWROK软件H5脚本执行与进度显示
AIWROK软件H5脚本执行与进度显示 .
信息发布软件AIWROK软件根据时间段执行异步任务支持多线程并行处理
AIWROK软件根据时间段执行异步任务支持多线程并行处理
信息发布软件H5自动开关执行脚本功能演示
H5自动开关执行脚本功能演示
信息发布软件AIWROK软件H5单选脚本运行示例
AIWROK软件H5单选脚本运行示例
信息发布软件H5任务脚本选择与执行中心
H5任务脚本选择与执行中心
信息发布软件H5里CheckBox控件演示
H5里CheckBox控件演示
信息发布软件AIWROK软件正则用法实际例子
AIWROK软件正则用法实际例子
信息发布软件AIWROK软件权限管理器实现
AIWROK软件权限管理器实现
信息发布软件AIWORK软件节点方法无碍示例子
AIWORK软件节点方法无碍示例子
信息发布软件JSON.stringify 和 JSON.parse 完整示例
JSON.stringify 和 JSON.parse 完整示例
信息发布软件AIWROK软件展示JavaScript各种语句标识符的用法
AIWROK软件展示JavaScript各种语句标识符的用法
信息发布软件JS巧妙地组合使用各种条件语句
JS巧妙地组合使用各种条件语句
信息发布软件AIWROK手机数据库MySQL数据库截图片批量上传操作脚本
AIWROK手机数据库MySQL数据库截图片批量上传操作脚本
信息发布软件HID中文输入智能打字功能
HID中文输入智能打字功能
信息发布软件AIWROK软件对象工具函数库例子
AIWROK软件对象工具函数库例子
信息发布软件AIWROK软件H5交互演示黄色主题
AIWROK软件H5交互演示黄色主题
信息发布软件H5单按钮执行脚本示例
H5单按钮执行脚本示例
信息发布软件苹果H5界面完整调用脚本示例
苹果H5界面完整调用脚本示例
信息发布软件AIWROK软件平台设备信息全面检测工具例子
AIWROK软件平台设备信息全面检测工具例子
信息发布软件AIWROK创建和放大日志窗口并展示动态内容
AIWROK创建和放大日志窗口并展示动态内容
信息发布软件AIWROK软件device相关方法获取设备信息例子
AIWROK软件device相关方法获取设备信息例子[/backcolor]
信息发布软件数据库MySQL实时内容随机调用
数据库MySQL实时内容随机调用
信息发布软件AIWROK软件分享一个特效苹果H5页面
AIWROK软件分享一个特效苹果H5页面
信息发布软件数据库MYQ业务流程心跳程序启动
数据库MYQ业务流程心跳程序启动
信息发布软件数据库MySQL功能支持创建表插入中文数据查询删除功能例子
数据库MySQL功能支持创建表插入中文数据查询删除功能例子
信息发布软件AIWROK软件Zip 高级操作复杂示例
AIWROK软件Zip 高级操作复杂示例
信息发布软件AIWROK软件txt_文件读写方法小结
AIWROK软件txt_文件读写方法小结
信息发布软件AIWROK软件file文件操作方法小结
AIWROK软件file文件操作方法小结
信息发布软件AIWORK软件配置读写H5演示配套脚本
AIWORK软件配置读写H5演示配套脚本
信息发布软件AIWROK配置读写功能演示示例
AIWROK配置读写功能演示示例
信息发布软件AIWROK截图缓存工具
AIWROK截图缓存工具
信息发布软件AIWROK线程许可证工具
AIWROK线程许可证工具
信息发布软件整理了AIWROK环境下常用的Date对象和sleep对象方法
整理了AIWROK环境下常用的Date对象和sleep对象方法
信息发布软件FastUI界面普通用法
FastUI界面普通用法
信息发布软件FastUI界面类[window]方法小结
FastUI界面类[window]方法小结 方法 1:close(关闭指定窗口)方法 2:closeAll(关闭所有窗口)方法 3:loadUI(加载 UI 界面)方法 4:onClose(监听窗口关闭事件)方法 5:onLoad(监听窗口加载事件)方法 6:setFull(设置窗口全屏)方法 7:setHeight(设置窗口高度)方法 8:setHidden(隐藏窗口)方法 9:setLeft(设置窗口 X 轴坐标)方法 10:setTop(设置窗口 Y 轴坐标)方法 11:setVisable(显示隐藏的窗口)方
信息发布软件AIWROK软件按钮监听UI界面与事件监听功能演示
AIWROK软件按钮监听UI界面与事件监听功能演示.
信息发布软件AWIROK软件多选[uiCheckBox]方法小结
AWIROK软件多选方法小结 方法一:findByID 加载多选控件方法二:getAllChecked 获取所有选中项方法三:getAllSelect 获取所有选项方法四:getChecked 获取某个选项是否选中方法五:setChecked 设置某个选项是否选中方法六:setCheckeds 设置多个选项是否选中方法七:setHeight 设置高度
信息发布软件AIWROK日志演示开启日志显示 → 放大 → 关闭代码
AIWROK日志演示开启日志显示 → 放大 → 关闭代码
信息发布软件&#127983;AIWROK数组方法高级应用案例
🏯AIWROK数组方法高级应用案例
信息发布软件AIWROK软件日志悬浮窗简化版自动切换位置
AIWROK软件日志悬浮窗简化版自动切换位置
信息发布软件AIWROK软件String实例演示
AIWROK软件String实例演示
信息发布软件AIWROK软件S内置String类[String]方法小结
AIWROK软件S内置String类[String]方法小结 方法 1:charAt[/backcolor]方法 2:charCodeAt[/backcolor]方法 3:indexOf[/backcolor]方法 4:lastIndexOf[/backcolor]方法 5:length[/backcolor]方法 6:match[/backcolor]方法 7:replace[/backcolor]方法 8:replaceAll[/backcolor]方法 9:split[/backcolor]方法 10:startsWith[/backcolor]方法 11:substr[/backcolor]方法 12:substring[/backcolor]方法 13:trim[/backcol
信息发布软件AIWROK软件完整的WebSocket客户端示例
这段代码是一个完整的WebSocket客户端示例,用于连接到指定的WebSocket服务器并处理各种事件。具体来说,代码的作用如下: 定义服务器地址:首先定义了一个服务器的IP地址和端口号 var ip = "154.37.221.104:8886";。 创建WebSocket对象:尝试创建一个新的WebSocket对象 var ws = new WebSocket();。注意,这里的 new ws() 应该是 new WebSocket()。 添加事件监听器:代码中尝试为WebSocket对象添加事件监听器,但这里有一个错误。
信息发布软件AIWROK软件苹果系统中实现四种基本滑动操作
AIWROK软件苹果系统中实现四种基本滑动操作
信息发布软件hid的滑动没有百分比坐标滑动吗
hid的滑动没有百分比坐标滑动吗
信息发布软件单选控件[uiRadioButton]方法小结
单选控件方法小结 方法 1:加载单选控件[/backcolor]方法 2:获取选中项[/backcolor]方法 3:设置高度[/backcolor]方法 4:设置选中项[/backcolor]
信息发布软件AIWROK软件无障碍触摸操作示例:点击、左右滑动、上下滑动实例
AIWROK软件无障碍触摸操作示例:点击、左右滑动、上下滑动实例
信息发布软件AIWROK软件安卓随机工具应用函数生成
AIWROK软件安卓随机工具应用函数生成
信息发布软件用在AIWORK软件代码中的实用符号分类整理2
用在AIWORK软件代码中的实用符号分类整理2 软件IDE用Emoji符号分类整理(含用途说明)一、表情与情感1. 微笑 [*]😀 笑脸(基础开心反馈,用于操作成功后的友好提示) [*]😃 笑脸大眼睛(强化开心情绪,用于重要任务完成后的积极反馈) [*]😄 笑脸和微笑的眼睛(温和友好的状态,用于日常交互中的正向回应) [*]😁 带着微笑的眼睛(轻松愉悦的反馈,用于轻度成功或趣味操作) [*]
信息发布软件AIWROK软件图像二值化的各种方法和应用场景
AIWROK软件图像二值化的各种方法和应用场景
信息发布软件AIWROK软件找图区分页面变化和卡死状态
AIWROK软件找图区分页面变化和卡死状态
信息发布软件AIWROK苹果系统Map 数据管理[map]小结
AIWROK苹果系统Map 数据管理[map]小结 方法一:add(添加键值对)[/backcolor]方法二:delete(删除指定键值对)[/backcolor]方法三:clear(清空所有键值对)[/backcolor]方法四:get(根据键获取值)[/backcolor]方法五:getAllValue(获取所有值)[/backcolor]方法六:toString(转换为字符串)[/backcolor]完整示例:

QQ|( 京ICP备09078825号 )

本网站信息发布软件,是可以发布论坛,发送信息到各大博客,各大b2b软件自动发布,好不夸张的说:只要手工能发在电脑打开IE能发的网站,用这个宣传软件就可以仿制动作,进行推送发到您想发送的B2B网站或是信息发布平台上,不管是后台,还是前台,都可以进行最方便的广告发布,这个广告发布软件,可以按月购买,还可以试用软件,对网站的验证码也可以完全自动对信息发布,让客户自动找上门,使企业轻松实现b2b发布,这个信息发布软件,均是本站原创正版开发,拥有正版的血统,想要新功能,欢迎提意见给我,一好的分类信息群发软件在手,舍我其谁。QQ896757558

GMT+8, 2026-2-4 18:00 , Processed in 1.147818 second(s), 56 queries .

宣传软件--信息发布软件--b2b软件广告发布软件

快速回复 返回顶部 返回列表