去看一下《java安全性编程指南》

解决方案 »

  1.   

    MD5算法加密
    public String generatemd5string(String csinput)
        {
            byte[] b, b2 ;
            StringBuffer buf ;
            String csreturn = null ;        try
            {
                b = csinput.getBytes("iso-8859-1") ;
                MessageDigest md = MessageDigest.getInstance("MD5") ;
                md.update(b) ;
                b2 = md.digest() ;            buf = new StringBuffer(b2.length * 2) ;
                for (int nLoopindex = 0 ; nLoopindex < b2.length ; nLoopindex++)
                {
                    if ( ( (int) b2[nLoopindex] & 0xff) < 0x10)
                    {
                        buf.append("0") ;
                    }
                    buf.append(Long.toString( (int) b2[nLoopindex] & 0xff, 16)) ;
                }
                csreturn = new String(buf) ;
            }
            catch (Exception e)
            {
                e.printStackTrace() ;
                csreturn = null ;
            }        return csreturn ;
        }