首先我们用到的是

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. mysql 存储引擎介绍

    一  存储引擎解释 首先确定一点,存储引擎的概念是MySQL里面才有的,不是所有的关系型数据库都有存储引擎这个概念,后面我们还会说,但是现在要确定这一点. 在讲清楚什么是存储引擎之前,我们先来个比喻, ...

  2. day27 粘包及粘包的解决方案

    1.   粘包现象 先了解一个词MTU MTU是Maximum Transmission Unit的缩写.意思是网络上传送的最大数据包.MTU的单位是字节. 大部分网络设备的MTU都是1500个字节, ...

  3. JavaScript trim 实现去除字符串首尾指定字符的简单方法

    String.prototype.trim = function (char, type) { if (char) { if (type == 'left') { return this.replac ...

  4. hdu 6287

    选出来比较合适的博客 https://blog.csdn.net/Tony5t4rk/article/details/80490711 https://blog.csdn.net/Game_Acm/a ...

  5. flume failed to start agent because dependencies were not found in classpath

    FLUME_CLASSPATH=/root/flume/lib/ copied comon jar files from hadoop folder to the flume folder. cp / ...

  6. pdf.js使用爬过的坑

    最近项目里需要做一个在浏览器直接预览pdf的功能,有些浏览器可以直接预览pdf文件,但是有些不能(不要躲,说的就是你IE)查资料普遍推荐pdf.js,兼容能到ie9,很不错了. 1. 从pdf.js官 ...

  7. 研磨设计模式学习笔记3--适配器模式Adapter

    需求:制作一个日志管理系统,分为2个版本,第一版制作一个将日志存在本地文件的管理系统,第二版制作一个存储在数据库的管理系统,同时,第二版兼容第一版. 优点:可以复用现有功能,无需重新开发. 一.第一版 ...

  8. Object类中有哪些方法

    equals().hashCode().wait().notify().notifyAll().toString().clone().getClass().finalize()

  9. 牛客网练习赛28A

    题目链接:https://www.nowcoder.com/acm/contest/200/A 链接:https://www.nowcoder.com/acm/contest/200/A来源:牛客网 ...

  10. ubuntu下安装录屏软件

    sudo add-apt-repository ppa:maarten-baert/simplescreenrecorder sudo apt-get update sudo apt-get inst ...