首先我们用到的是

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. keepalived企业管理

    实践案例一:更改nginx反向代理只监听vip地址 10.0.0.3/nana.html 可以使用 10.0.0.5/nana.html  不可以使用 10.0.0.6/nana.html  不可以使 ...

  2. java 数据库连接

    一.JDBC(Java Database Connectivity) JDBC是Java语言中访问数据库的应用程序接口,可以为多种关系数据库提供统一访问. jdbc.properties jdbc.d ...

  3. hive支持事务及单行操作 update delete

    测试环境  Hive 1.2.1000.2.6.0.3-8 set hive.support.concurrency=true; set hive.exec.dynamic.partition.mod ...

  4. eclipse使用STS插件 报错:SocketTimeoutException: Read timed out

    新建boot项目后,提示: SocketTimeoutException: Read timed out 解决: 在eclipse.ini末尾,追加: -Djava.net.preferIPv4Sta ...

  5. 技巧:开启ubuntu系统桌面上的右键进入terminal命令行控制台功能

    $ sudo apt-get install nautilus-open-terminal 执行上述命令,重启. 重启命令: $ sudo reboot 注意:需要联网

  6. Hbase 表操作

    1. list 操作 2. 创建table column family, 3. 插入数据: put 'user' 3. 检索数据: scan table

  7. MapReduce 调优-Combiner

    下图是演示了Combiner的好处 因为我们知道Hadoop的好处在于集群中有很多小的机器,组成了一个庞大的集群,把一个大的计算任务后者说复杂的计算过程分发到了一个个小的机器上面.但是这个集群一个致命 ...

  8. public class 与 class 的区别

    public class 与 class 的区别 1.一个类前面的public是可有可无的 2.如果一个类使用 public 修饰,则文件名必须与类名一致 3.如果一个类前面没有使用public修饰, ...

  9. 动态资源不缓存 filter

    package com.itheima.web.filter; import java.io.IOException; import javax.servlet.Filter; import java ...

  10. Node调试之node-inspect工具

    1.全局安装node-inspect模块: npm install -g node-inspect 2.通过谷歌浏览器打开:chrome://flags/#enable-devtools-experi ...