1、POST/GET 这个不用多说了。
2、 Encrypting QueryStrings with .NET
CODE:
C#:
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Security.Cryptography;
public class Encryption64
...{
//private byte[] key = {};
//private byte[] IV = {10, 20, 30, 40, 50, 60, 70, 80}; // it can be any byte value
public static string Decrypt(string stringToDecrypt,
string sEncryptionKey)
...{
byte[] key = ...{ };
byte[] IV = ...{ 10, 20, 30, 40, 50, 60, 70, 80 };
byte[] inputByteArray = new byte[stringToDecrypt.Length];
try
...{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (System.Exception ex)
...{
throw ex;
}
}
public static string Encrypt(string stringToEncrypt,
string sEncryptionKey)
...{
byte[] key = ...{ };
byte[] IV = ...{ 10, 20, 30, 40, 50, 60, 70, 80 };
byte[] inputByteArray; //Convert.ToByte(stringToEncrypt.Length)
try
...{
key = Encoding.UTF8.GetBytes(sEncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (System.Exception ex)
...{
throw ex;
}
}
}
VB.NET
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography
Public Class Encryption64
Private key() As Byte = {}
Private IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Public Function Decrypt(ByVal stringToDecrypt As String, _
ByVal sEncryptionKey As String) As String
Dim inputByteArray(stringToDecrypt.Length) As Byte
Try
key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))
Dim des As New DESCryptoServiceProvider()
inputByteArray = Convert.FromBase64String(stringToDecrypt)
Dim ms As New MemoryStream()
Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), _
CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
Return encoding.GetString(ms.ToArray())
Catch e As Exception
Return e.Message
End Try
End Function
Public Function Encrypt(ByVal stringToEncrypt As String, _
ByVal SEncryptionKey As String) As String
Try
key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8))
Dim des As New DESCryptoServiceProvider()
Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes( _
stringToEncrypt)
Dim ms As New MemoryStream()
Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), _
CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Return Convert.ToBase64String(ms.ToArray())
Catch e As Exception
Return e.Message
End Try
End Function
End Class
Default.aspx.cs
//加密URL
protected void Page_Load(object sender, EventArgs e)
...{
string strValues = "http://blog.youkuaiyun.com/slimboy123";
string strEnURL = "Default2.aspx?url="
+ encryptQueryString(strValues);
Response.Redirect(strEnURL);
}
public string encryptQueryString(string strQueryString)
...{
return Encryption64.Encrypt(strQueryString, "!#$a54?3");
}
Default2.aspx.cs
//解密URL
protected void Page_Load(object sender, EventArgs e)
...{
if (Request.QueryString["url"] != null)
...{
Response.Write(decryptQueryString(Request.QueryString["url"].Trim().Replace(" ","+")));
}
}
public string decryptQueryString(string strQueryString)
...{
return Encryption64.Decrypt(strQueryString, "!#$a54?3");
}