我们如何加密查询字符串的值?在另一页解密。 [英] How can we encrypted value of query string & decrypted in another page.

查看:71
本文介绍了我们如何加密查询字符串的值?在另一页解密。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的查询字符串代码:

Response.Redirect("Default.aspx?name=" + txtname.Text + "&add=" + txtaddress.Text + "&email=" + txtemail.Text + "&city=" + txtcity.Text + "&state=" + txtstate.Text + "&zip=" +txtcountry.Text + "&country=" +txtcountry.Text+ "&payment="+txtamount.Text +"&specialcondition="+txtspeclcondition.Text);

推荐答案

为什么要通过查询传递这些值?将它们放在会话变量中并检查Default.aspx(如果已设置)。如果设置,请处理它并从会话中删除。如果没有,表现正常。



但是如果你坚持加密,请查看这个简短的教程: http://www.dijksterhuis.org/encrypting-decrypting-string/ [ ^ ]。我不会单独加密每个字段值,我会序列化字典(例如json字符串),加密,编码到base64(参见教程) - 另一端是反向过程。
Why passing these values via query? Put them in a session variable and check in Default.aspx if this one is set or not. If set, handle it and delete from the session. If not, behave normally.

But if you stick to crypto, check out this short tutorial: http://www.dijksterhuis.org/encrypting-decrypting-string/[^]. I would not encrypt every field value separately, I would serialize the dictionary (to json string for example), encrypt, encode to base64 (see the tutorial) - and at the other end the reverse process.


Hey Guys I have solved this. Just enjoying by my Code !

//-------- Code For Encrypt----------------------------------

 public string EncryptString(string ClearText)
    {

        byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText);

        System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();

        MemoryStream ms = new MemoryStream();
        byte[] rgbIV = Encoding.ASCII.GetBytes("ryojvlzmdalyglrj");
        byte[] key = Encoding.ASCII.GetBytes("hcxilkqbbhczfeultgbskdmaunivmfuo");
        CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV),
   CryptoStreamMode.Write);

        cs.Write(clearTextBytes, 0, clearTextBytes.Length);

        cs.Close();

        return Convert.ToBase64String(ms.ToArray());
    }


//-------- Code For Decrypt----------------------------------



public string DecryptString(string query)
    {
        string result = "";

        try
        {
            MemoryStream ms = null;
            if (query != "")
            {
                string EncryptedText = query;
                EncryptedText = EncryptedText.Replace(' ', '+');

                byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
                ms = new MemoryStream();
                System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();

                byte[] rgbIV = Encoding.ASCII.GetBytes("ryojvlzmdalyglrj");
                byte[] key = Encoding.ASCII.GetBytes("hcxilkqbbhczfeultgbskdmaunivmfuo");

                CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV),
                CryptoStreamMode.Write);

                cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);

                cs.Close();
                result = Encoding.UTF8.GetString(ms.ToArray());
            }
        }
        catch (Exception ex)
        {
            RecordExceptions(ex);
        }
        return result;
    }


这篇关于我们如何加密查询字符串的值?在另一页解密。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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