AES 加密解密

///

/// AES加密
///

/// 被加密的明文 /// 密钥 /// 向量 /// 密文
public static Byte[] AESEncrypt(Byte[] Data, String Key, String Vector)
{
Byte[] bKey = new Byte[32];
Array.Copy(Encoding.UTF8.GetBytes(Key.PadRight(bKey.Length)), bKey, bKey.Length);
Byte[] bVector = new Byte[16];
Array.Copy(Encoding.UTF8.GetBytes(Vector.PadRight(bVector.Length)), bVector, bVector.Length);

Byte[] Cryptograph = null; // 加密后的密文

Rijndael Aes = Rijndael.Create();
try
{
// 开辟一块内存流
using (MemoryStream Memory = new MemoryStream())
{
// 把内存流对象包装成加密流对象
using (CryptoStream Encryptor = new CryptoStream(Memory,
Aes.CreateEncryptor(bKey, bVector),
CryptoStreamMode.Write))
{
// 明文数据写入加密流
Encryptor.Write(Data, 0, Data.Length);
Encryptor.FlushFinalBlock();

Cryptograph = Memory.ToArray();
}
}
}
catch
{
Cryptograph = null;
}

return Cryptograph;
}

///

/// AES解密
///

/// 被解密的密文 /// 密钥 /// 向量 /// 明文
public static Byte[] AESDecrypt(Byte[] Data, String Key, String Vector)
{
Byte[] bKey = new Byte[32];
Array.Copy(Encoding.UTF8.GetBytes(Key.PadRight(bKey.Length)), bKey, bKey.Length);
Byte[] bVector = new Byte[24];
Array.Copy(Encoding.UTF8.GetBytes(Vector.PadRight(bVector.Length)), bVector, bVector.Length);

Byte[] original = null; // 解密后的明文

Rijndael Aes = Rijndael.Create();
try
{
// 开辟一块内存流,存储密文
using (MemoryStream Memory = new MemoryStream(Data))
{
// 把内存流对象包装成加密流对象
using (CryptoStream Decryptor = new CryptoStream(Memory,
Aes.CreateDecryptor(bKey, bVector),
CryptoStreamMode.Read))
{
// 明文存储区
using (MemoryStream originalMemory = new MemoryStream())
{
Byte[] Buffer = new Byte[1024];
Int32 readBytes = 0;
while ((readBytes = Decryptor.Read(Buffer, 0, Buffer.Length)) > 0)
{
originalMemory.Write(Buffer, 0, readBytes);
}

original = originalMemory.ToArray();
}
}
}
}
catch
{
original = null;
}

return original;
}

ASP.NET中c#的URL编码处理

ASP.NET中c#的URL编码处理
要解决的问题:
将下面的URL作为一个参数传到其他的页面
1 http://domain/de.apx?uid=12&page=15
2 url后面的参数中出现汉字等,如: ….aspx?title=起重机
在出现上面的情况的时候,必须经过一个RUL编码和解码的过程,否则会出现错误.
代码如下:
复制内容到剪贴板代码:

//传值
string temp = ” 添加到收藏夹“);

//在另外一个文件中取从上面传的值
if (Request.QueryString["url"] != null)
{
string url = Server.UrlDecode(Request.QueryString["url"].ToString());
this.txtAddress.Text = url;
}
if (Request.QueryString["title"] != null)
{
string title = Server.UrlDecode(Request.QueryString["title"].ToString());
this.txtTitle.Text = title;
}

javascript URL编码方法的比较(escape encodeURI encodeURIComponent)

javascript中存在几种对URL字符串进行编码的方法:escape(),encodeURI(),以及encodeURIComponent() 。这几种编码所起的作用各不相同。

escape() 方法:

采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符 都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字 )。比如,空格符对应的编码是%20。

针对非ASCII字符

第一步 就是你是某种字符(gbk/utf-8),

第二部 将这种字符的(gbk/utf-8)得到unicode 的 16进制的字节码

第三部 将这些字节码进行url编码

不会被此方法编码的字符: @ * / +

encodeURI() 方法:

把URI字符串采用UTF-8编码格式转化成escape格式的字符串。

不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + ‘

针对非ASCII字符

第一步 就是你是某种字符(gbk/utf-8),

第二部 将这种字符的(gbk/utf-8)得到utf-8的 16进制的字节码

第三部 将这些字节码进行url编码

encodeURIComponent() 方法:

把 URI字符串采用UTF-8编码格式转化成escape格式的字符串。 与encodeURI()相比,这个方法将对更多的字符进行编码,比如 / 等字符。所以如果字符串里面包含了URI的几个部分的话 ,不能用这个方法来进行编码,否则 / 字符被编码之后URL将显示错误。

针对非ASCII字符

第一步 就是你是某种字符(gbk/utf-8),

第二部 将这种字符的(gbk/utf-8)得到utf-8的 16进制的字节码

第三部 将这些字节码进行url编码

因此,对于中文字符串来说,如果不希望把字符串编码格式转化成UTF-8格式的(比如原页面和目标页面的charset是一致的时候),只需要使用 escape 。如果你的页面是GB2312或者其他的编码,而接受参数的页面是UTF-8编码的,就要采用encodeURI或者 encodeURIComponent。

jquery 京东、凡客,等电子商城产品内页多图展示代码

jquery京东产品内页多图展示代码,鼠标移到图片上有放大效果,方便查看产品细节,此代码适合网店产品展示,大图尺寸650×650,推荐下载!
如图:

演示地址:http://www.orzbook.com/demo/product-images/index.html

ASP.NET MVC中的跳转

一、

1.使用传统的Response.Redirect
例如
string url = “/account/create”;
Response.Redirect(url);

2.使用MVC新的RedirectToAction(“Action name”,”Controller name”);
return RedirectToAction(“Index”,”Home”);//跳转到首页。
第一个参数是action 的名字,第二个参数是控制器controller的名字,方法返回的是个ActionResult.也就是返回视图。

二、

最近在spring mvc中遇到了如何实现页面跳转的问题.比如在页面A中的提交按钮用户提交后,需要重定向到另外一个新的页面,并且有可能要把一些参数带
过去.
这其实在实现中有两个方法
1 在controller中实现redirect,可以使用sendRedirect()方法,然后返回

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception
{

……..
response.sendRedirect(“photohouxuandetail.do?pid=”+pid);
return null;
}
2 还可以用redirect来实现,这样viewResolver认为是重定向操作,不再渲染该视图了,而是直接向客户端发出redirect响应
return new ModelAndView(“redirect:photohouxuandetail.do?pid=”+pid);

三、
C# code

public ActionResult Details(string id)
{
ViewData["Message"] = “成功”;
return View();
}

Details.aspx:

C# code

$(document).ready(function(){
if(ViewData["Message"])
alert(ViewData["Message"].ToString());
});