href='http://somepage.aspx?employeeid=<%#yourfunction(DataBinder.Eval(Container.DataItem,"employeeID")%>'   
    
    
  protected/public   string   function()   
  {   
  }求这样一个 function() 的加密算法,或其他加密算法.谢谢大家.

解决方案 »

  1.   

    啥意思?Encrypt?
    Server.UrlEncode()?
    MD5?
    Base64?
      

  2.   

    Des算法比较符合,因为URL参数还需要解密
     
            /// <summary>
            /// DES可逆加密
            /// </summary>
            public class Des
            {
                          /// <summary>
                /// 加密。注意:sKey输入密码的时候,必须使用英文字符,区分大小写,且字符数量是8个,不能多也不能少,否则出错。
                /// </summary>
                public static string Encrypt(string pToEncrypt, string sKey)
                {
                    
                    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                    //把字符串放到byte数组中  
                    //原来使用的UTF8编码,我改成Unicode编码了,不行  
                    byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
                    //byte[]  inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);                  //建立加密对象的密钥和偏移量  
                    //原文使用ASCIIEncoding.ASCII方法的GetBytes方法  
                    //使得输入密码必须输入英文文本  
                    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                    MemoryStream ms = new MemoryStream();
                    CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                    //Write  the  byte  array  into  the  crypto  stream  
                    //(It  will  end  up  in  the  memory  stream)  
                    cs.Write(inputByteArray, 0, inputByteArray.Length);
                    cs.FlushFinalBlock();
                    //Get  the  data  back  from  the  memory  stream,  and  into  a  string  
                    StringBuilder ret = new StringBuilder();
                    foreach (byte b in ms.ToArray())
                    {
                        //Format  as  hex  
                        ret.AppendFormat("{0:X2}", b);
                    }
                    return ret.ToString();
                }            /// <summary>
                /// 解密。
                /// </summary>
                public static string Decrypt(string pToDecrypt, string sKey)
                {
                    DESCryptoServiceProvider des = new DESCryptoServiceProvider();                //Put  the  input  string  into  the  byte  array  
                    byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
                    for (int x = 0; x < pToDecrypt.Length / 2; x++)
                    {
                        int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                        inputByteArray[x] = (byte)i;
                    }                //建立加密对象的密钥和偏移量,此值重要,不能修改  
                    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                    MemoryStream ms = new MemoryStream();
                    CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                    //Flush  the  data  through  the  crypto  stream  into  the  memory  stream  
                    cs.Write(inputByteArray, 0, inputByteArray.Length);
                    cs.FlushFinalBlock();                //Get  the  decrypted  data  back  from  the  memory  stream  
                    //建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象  
                    StringBuilder ret = new StringBuilder();                return System.Text.Encoding.UTF8.GetString(ms.ToArray());
                }        }
      

  3.   

    支持3楼,参考
    http://blog.csdn.net/iStarSoft/archive/2009/07/18/4359081.aspx
      

  4.   

    加密参数有必要么?如果非要加密,不如后台提交。既然是URL参数,那么搞这么麻烦无益无义啊。
      

  5.   

    Server.UrlEncode()
    这个在一般情况下应该就够用了,特殊的参数就在后台去加密用Post去提交。。
      

  6.   

    加密方法可用des等,还可使用HttpUtility.UrlEncode编码
    public string SHA1(string source) 

        return FormsAuthentication.HashPasswordForStoringInConfigFile(source, "SHA1"); 

    public string MD5(string source) 

        return FormsAuthentication.HashPasswordForStoringInConfigFile(source, "MD5");; 

    public string Encode(string data) 

        byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); 
        byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); 
        int i = cryptoProvider.KeySize; 
        MemoryStream ms = new MemoryStream(); 
        CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);     StreamWriter sw = new StreamWriter(cst); 
        sw.Write(data); 
        sw.Flush(); 
        cst.FlushFinalBlock(); 
        sw.Flush(); 
        return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); } public string Decode(string data) 

        byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); 
        byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);     byte[] byEnc; 
        try 
        { 
            byEnc = Convert.FromBase64String(data); 
        } 
        catch 
        { 
            return null; 
        }     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); 
        MemoryStream ms = new MemoryStream(byEnc); 
        CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read); 
        StreamReader sr = new StreamReader(cst); 
        return sr.ReadToEnd(); 

    using System.Security.Cryptography;
    ...
    public string Encode(string data)
    {
    byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
    byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
    DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
    int i = cryptoProvider.KeySize;
    MemoryStream ms = new MemoryStream();
    CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);
    StreamWriter sw = new StreamWriter(cst);
    sw.Write(data);
    sw.Flush();
    cst.FlushFinalBlock();
    sw.Flush();
    return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
    }
    public string Decode(string data)
    {
    byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
    byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);
    byte[] byEnc;
    try
    {
    byEnc = Convert.FromBase64String(data);
    }
    catch
    {
    return null;
    }
    DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
    MemoryStream ms = new MemoryStream(byEnc);
    CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
    StreamReader sr = new StreamReader(cst);
    return sr.ReadToEnd();
    }private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; 
    public static string EncryptDES(string encryptString, string encryptKey) 

        try 
        { 
            byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); 
            byte[] rgbIV = Keys; 
            byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); 
            DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider(); 
            MemoryStream mStream = new MemoryStream(); 
            CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); 
            cStream.Write(inputByteArray, 0, inputByteArray.Length); 
            cStream.FlushFinalBlock(); 
            return Convert.ToBase64String(mStream.ToArray()); 
        } 
        catch 
        { 
            return encryptString; 
        } 
    } public static string DecryptDES(string decryptString, string decryptKey) 

        try 
        { 
            byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey); 
            byte[] rgbIV = Keys; 
            byte[] inputByteArray = Convert.FromBase64String(decryptString); 
            DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider(); 
            MemoryStream mStream = new MemoryStream(); 
            CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write); 
            cStream.Write(inputByteArray, 0, inputByteArray.Length); 
            cStream.FlushFinalBlock(); 
            return Encoding.UTF8.GetString(mStream.ToArray()); 
        } 
        catch 
        { 
            return decryptString; 
        } 
    }