C#用使用Des加密后如何在ASP中解密
我通过以下代码对我需要加密的信息加密了,并附加到链接中,进行参数传递。但要是接收方是ASP语言编写的,请问如何在ASP解密由以下函数加密的信息。
已尝试过网络上部分N人的算法,都解密不成功
public static string Encrypt(string Text,string sKey) 

   DESCryptoServiceProvider des = new DESCryptoServ.iceProvider(); 
   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.   


       
            private void button1_Click(object sender, EventArgs e)
            {
                string _Test = Encrypt("a", "aaa");
                this.Text=GetText(_Test,"aaa");
            }        public static string Encrypt(string Text, string sKey)
            {
                System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.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();
                System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                ms.Position = 0;
                StringBuilder ret = new StringBuilder();
                foreach (byte b in ms.ToArray())
                {
                    ret.AppendFormat("{0:X2}", b);
                }
                return ret.ToString();
            }        public string Decrypt(string p_BytesText, string sKey)
            {
                string _TempText = p_BytesText;
                byte[] _DataBytes = new byte[p_BytesText.Length / 2];            for (int i = 0; i != _DataBytes.Length; i++)
                {
                    _DataBytes[i] = Convert.ToByte(_TempText.Substring(0, 2), 16);
                    _TempText = _TempText.Remove(0, 2);
                }            System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();
              
                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();            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(),System.Security.Cryptography.CryptoStreamMode.Write);            
                cs.Write(_DataBytes, 0, _DataBytes.Length);
                cs.FlushFinalBlock();            
                byte[] _StringByte = ms.ToArray();
                return Encoding.Default.GetString(_StringByte);
               
            }
    这是没问题的啊
      

  2.   

    ASP调用c# 类方法。应该可以的
      

  3.   

    看看在asp中有没有提供(准确的说是javascript或者vbscript中)有没有提供相应的方法,如果没有就得考虑利用原生类库或者使用web service提供相应的功能了。