首先我们用到的是

DESCryptoServiceProvider 类

对此微软给出的解释是

定义访问数据加密标准 (DES) 算法的加密服务提供程序 (CSP) 版本的包装对象。无法继承此类。

接下来是接受参数页面的方法:

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient; namespace Url加密
{
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
GetDate();
}
} Byte[] byKey64 = { , , , , , , , };
Byte[] Iv64 = { , , , , , , , }; public string Decrypt(string strText)
{
Byte[] inputByteArray = new byte[strText.Length];
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey64, Iv64), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
} public string content = string.Empty; public void GetDate()
{
string sql = "SELECT * FROM [Info] WHERE [Id]=@id";
string ConStr = "Data Source=.;Initial Catalog=DBTest;User ID=sa;Password=123456";
SqlParameter para = new SqlParameter("@id", Decrypt(Request.QueryString["id"])); using (SqlConnection conn = new SqlConnection(ConStr))
{
conn.Open();
SqlCommand comm = new SqlCommand(sql.ToString(), conn);
comm.Parameters.Add(para);
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
content = reader["Details"].ToString();
}
reader.Close();
}
}
}
}

我用的是repeater的绑定方式

然后是传入ID参数的页面后台代码如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient; namespace Url加密
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
GetDate();
}
} Byte[] Iv64 = { , , , , , , , };
Byte[] byKey64 = { , , , , , , , };
public string Encrypt(string strText)
{
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
Byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey64, Iv64), CryptoStreamMode.Write);
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
} public string id = string.Empty; public void GetDate()
{
string sql = "SELECT * FROM [dbo].[Info]";
string ConStr="Data Source=.;Initial Catalog=DBTest;User ID=sa;Password=123456";
using(SqlConnection conn=new SqlConnection(ConStr))
{
conn.Open();
SqlCommand comm=new SqlCommand(sql.ToString(),conn);
DataSet dt = new DataSet();
SqlDataAdapter sdt = new SqlDataAdapter(sql.ToString(),conn);
sdt.Fill(dt);
this.Repeater1.DataSource = dt.Tables[];
this.Repeater1.DataBind();
}
}
}
}

他的前台参数绑定:

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<a href="Content.aspx?id=<%#Encrypt(Eval("Id").ToString())%>"><%#Eval("Title") %></a>
</ItemTemplate>
</asp:Repeater>

请注意,对于ID转换成为字符串这一步很重要。以上就是我的个人心得了。希望有大神能够继续指教完善,同时也参考了网上的代码资料。对此表示感谢

制作URL以GET方式提交的简单加密程序的更多相关文章

  1. 8)post方式提交和简单那处理

    带有htmll的代码: 实现简单的计算器 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  2. ASP.NET 最全的POST提交数据和接收数据 —— (1) 用url传参方式

    //1.对象提交,字典方式 //接口方:public ActionResult GetArry(Car model) public void PostResponse() { HttpWebReque ...

  3. jquery.form.js实现将form提交转为ajax方式提交的使用方法

    本文实例讲述了jquery.form.js实现将form提交转为ajax方式提交的方法.分享给大家供大家参考.具体分析如下: 这个框架集合form提交.验证.上传的功能. 这个框架必须和jquery完 ...

  4. Android 使用Post方式提交数据(登录)

    在Android中,提供了标准Java接口HttpURLConnection和Apache接口HttpClient,为客户端HTTP编程提供了丰富的支持. 在HTTP通信中使用最多的就是GET和POS ...

  5. 解决ajax get post方式提交中文参数乱码问题

    最近在工作中遇到,使用ajax get方式提交中文参数的时候出现乱码,通过上网搜索,总结出比较简单的两种解决方案: 第一种,由于tomcat默认的字符集是ISO-8859-1,修改Tomcat中的se ...

  6. jquery.form.js实现将form提交转为ajax方式提交的方法

    本文实例讲述了jquery.form.js实现将form提交转为ajax方式提交的方法.分享给大家供大家参考.具体分析如下: 这个框架集合form提交.验证.上传的功能. 这个框架必须和jquery完 ...

  7. 温故而知新: 关于 js Form 方式提交的一些新认知

    这里介绍的是通过js进行异步form提交,而不是表单Form Submit提交. 提交方式主要有以下两种: 参数为字符串方式的提交,如:a=b&c=d formData方式提交, 如:new ...

  8. 使用GET方式提交的表单遇到的问题

    经常使用表单,一直使用的都是POST方式,POST将数据封装到请求体中,相对于GET安全一点:而POST处理中文编码问题也比GET简单(GET需要将URL编码,后台接受到后还需要解码).今天我想要使用 ...

  9. 采用DoGet方式提交中文,乱码产生原因分析及解决办法

    前段时间某功能在测试机器上出现乱码,情况如下:   现象:           调试搜索功能时,通过doGet方法提交到后台的中文参数在本地和开发测试机器上为乱码(Action层),在测试人员测试机器 ...

随机推荐

  1. Ansible自动化运维工具

    ansible软件介绍 python语言是运维人员必会的语言!  ansible是一个基于Python开发的自动化运维工具!(saltstack)  其功能实现基于SSH远程连接服务!  ans ...

  2. mysql 中decimal中去掉后面多余的0

    #去除Decimal后面多余的0 #处理前SELECT '0.12000','1.203010','-0.20' #处理后SELECT 0+CAST('0.12000' AS CHAR),0+CAST ...

  3. linux面试题:删除一个目录下的所有文件,但保留一个指定文件

    面试题:删除一个目录下的所有文件,但保留一个指定文件 解答: 假设这个目录是/xx/,里面有file1,file2,file3..file10 十个文件 [root@oldboy xx]# touch ...

  4. 2.2 Go 常量与枚举

    package main import ( "fmt" "math" ) //常量 func cons(){ , //常量的数字在不明确指定类型的情况下,即可以 ...

  5. Cmder光标错位的问题&VSCode终端光标错位问题

    问题 本机中安装了 Cmder,几乎是0配置 ,同时在 VSCode 中设置默认终端为 Cmder,在 VSCode 中打开终端,显示如图: 这里光标实际的位置是 . 的后面,但是表现出来的是多一个空 ...

  6. 前后端分离之JWT用户认证

    在前后端分离开发时为什么需要用户认证呢?原因是由于HTTP协定是不储存状态的(stateless),这意味着当我们透过帐号密码验证一个使用者时,当下一个request请求时它就把刚刚的资料忘了.于是我 ...

  7. robotframework 常用快捷键

    重命名——>F2 执行用例——>F8 创建新工程——>ctrl+n 创建新测试套——>ctrl+shift+f 创建新用例——>ctrl+shift+t 创建新关键字—— ...

  8. Choose and divide(唯一分解定理)

    首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...

  9. Murano Weekly Meeting 2016.05.17

    Meeting time: 2016.May.17 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary:   1 ...

  10. 用Windows Live Writer离线写博客

    作为CSDN博客的菜鸟,我发现在线写博客很不方便,而且文字编辑也不方便,比如不能傻瓜化地修改字体和颜色."有志者自有千方百计,无志者只感千难万难."一番搜索后,我发现了Window ...