下面这段加密在java中怎么实现,谢谢了。
public static string Encrypt(string Text,string sKey) 

DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
byte[] inputByteArray; 
inputByteArray=Encoding.Default.GetBytes(Text); 
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); 
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); 
System.IO.MemoryStream ms=new System.IO.MemoryStream(); 
CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write); 
cs.Write(inputByteArray,0,inputByteArray.Length); 
cs.FlushFinalBlock(); 
StringBuilder ret=new StringBuilder(); 
foreach( byte b in ms.ToArray()) 

ret.AppendFormat("{0:X2}",b); 

return ret.ToString(); 

解决方案 »

  1.   

    md5加密,但是不知道Java怎么用,不会Java
      

  2.   

    没学过java,不知java里有没有类似的类可以调用
      

  3.   

    Java里面有CRC的类可以用 在Util包里面 楼主可以参考
    但是MD5的不知道最新的Java只不支持
    楼主可以去看看
      

  4.   

    public static string Encrypt(string Text,string sKey) 

        //声明一个基于DES加密算法的加密提供者,就是一个DES加密算法
       DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
       byte[] inputByteArray; 
       
       //将字符串文本转换成二进制数组
       inputByteArray=Encoding.Default.GetBytes(Text);    //此处应该添加代码判定sKey字符串的有效长度
       //将sKey的前8个字符串进行MD5汉斯摘要加密,将汉斯结果作为DES加密的密钥
       des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile      (sKey, "md5").Substring(0, 8)); 
       
       //将sKey的前8个字符串进行MD5汉斯摘要加密,将汉斯结果作为DES加密向量,也可以去sKey中的其他子串
       des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));    //创建一个内存流,用于取回加密的结果
       System.IO.MemoryStream ms=new System.IO.MemoryStream();    //创建一个加密流,并将内存输出流与加密流进行绑定,设置加密流为使用DES加密算法,流为写模式
       CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);    //将明文二进制数据写入流中
       cs.Write(inputByteArray,0,inputByteArray.Length);    //完成加密流中的所有数据加工,此语句必须有,要么流可能被截断,加密结果只是一部分,流是异步的,此语句等同等待加密流完成它的工作
       cs.FlushFinalBlock(); 
       //这里可以关闭加密流了 cs.Close();      //从内存输出流中读取加密结果,并组织成十六进制的字符串
       StringBuilder ret=new StringBuilder(); 
       foreach( byte b in ms.ToArray()) 
       { 
            ret.AppendFormat("{0:X2}",b); 
       } 
       return ret.ToString(); 
    }