查询字符串实际问题 [英] Query String Realted Question

查看:102
本文介绍了查询字符串实际问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有人帮助我如何不知道如何创建加密/解密的查询字符串..

how to create encrypted/decrypted query string if any one could help I don''t know much about it..

推荐答案

这是您的操作方式.. 点击此处 [
This is how you do it ..Click here[^]


first encrypt your string value using encryptor than pass to query string, than when you want to access value of query string, convert that value to string than using descriptor discrypt that value 


首先,您需要使用适当的加密算法对值进行加密,然后将此值作为查询字符串传递,从查询字符串中获取此值之后,请使用解密算法来获取实际值..


第一页-
Session [encryptionPassword] =超级机密";
字符串密码=会话[encryptionPassword] .Value.ToString();
字符串textToEncrypt =加密值";
加密的字符串= Crypto.Encrypt(textToEncrypt,secretcode);
Response.Redirect("pagename.aspx?a =" + encrypted);

第二页-

加密的字符串= Request.QueryString ["a"].ToString();
字符串密码=会话[encryptionPassword] .Value.ToString();
字符串原始= Crypto.Decrypt(已加密,密码);



First you need to encrypt the value using appropriate encryption algorithm then pass this values as a query string , after retrieving this value from query string , use decryption algorithm to get actual value..


first page--
Session[encryptionPassword] = "supersecret";
string secretcode = Session[encryptionPassword].Value.ToString();
string textToEncrypt = "value for encryption";
string encrypted = Crypto.Encrypt(textToEncrypt, secretcode );
Response.Redirect("pagename.aspx?a="+encrypted );

second page--

string encrypted = Request.QueryString["a"].ToString();
string secretcode = Session[encryptionPassword].Value.ToString();
string original = Crypto.Decrypt(encrypted, secretcode );



static public class Crypto

  {

      private static readonly byte[] salt = Encoding.ASCII.GetBytes("Ent3r your oWn S@lt v@lu# h#r3");



      public static string Encrypt(string textToEncrypt, string encryptionPassword)

      {

          var algorithm = GetAlgorithm(encryptionPassword);



          byte[] encryptedBytes;

          using (ICryptoTransform encryptor = algorithm.CreateEncryptor(algorithm.Key, algorithm.IV))

          {

              byte[] bytesToEncrypt = Encoding.UTF8.GetBytes(textToEncrypt);

              encryptedBytes = InMemoryCrypt(bytesToEncrypt, encryptor);

          }

          return Convert.ToBase64String(encryptedBytes);

      }



      public static string Decrypt(string encryptedText, string encryptionPassword)

      {

          var algorithm = GetAlgorithm(encryptionPassword);



          byte[] descryptedBytes;

          using (ICryptoTransform decryptor = algorithm.CreateDecryptor(algorithm.Key, algorithm.IV))

          {

              byte[] encryptedBytes = Convert.FromBase64String(encryptedText);

              descryptedBytes = InMemoryCrypt(encryptedBytes, decryptor);

          }

          return Encoding.UTF8.GetString(descryptedBytes);

      }



      // Performs an in-memory encrypt/decrypt transformation on a byte array.

      private static byte[] InMemoryCrypt(byte[] data, ICryptoTransform transform)

      {

          MemoryStream memory = new MemoryStream();

          using (Stream stream = new CryptoStream(memory, transform, CryptoStreamMode.Write))

          {

              stream.Write(data, 0, data.Length);

          }

          return memory.ToArray();

      }


      // Defines a RijndaelManaged algorithm and sets its key and Initialization Vector (IV)

      // values based on the encryptionPassword received.

      private static RijndaelManaged GetAlgorithm(string encryptionPassword)

      {

          // Create an encryption key from the encryptionPassword and salt.

          var key = new Rfc2898DeriveBytes(encryptionPassword, salt);



          // Declare that we are going to use the Rijndael algorithm with the key that we've just got.

          var algorithm = new RijndaelManaged();

          int bytesForKey = algorithm.KeySize / 8;

          int bytesForIV = algorithm.BlockSize / 8;

          algorithm.Key = key.GetBytes(bytesForKey);

          algorithm.IV = key.GetBytes(bytesForIV);

           return algorithm;

       }

 

    }


这篇关于查询字符串实际问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆