加密解密Url字符串,C#对Url进行处理,传递Url
string _QueryStringKey = "abcdefgh"; //URL传输参数加密Key
/// 加密URL传输的字符串
public string EncryptQueryString(string QueryString)
{
return Encrypt(QueryString, _QueryStringKey);
}
/// 解密URL传输的字符串
public string DecryptQueryString(string QueryString)
{
return Decrypt(QueryString, _QueryStringKey);
}
/// DEC 加密过程
public string Encrypt(string pToEncrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //把字符串放到byte数组中
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
//byte[] inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //建立加密对象的密钥和偏移量
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
MemoryStream ms = new MemoryStream(); //使得输入密码必须输入英文文本
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
///
/// DEC 解密过程
///
///
///
///
public string Decrypt(string pToDecrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //建立加密对象的密钥和偏移量,此值重要,不能修改
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder(); //建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
加密解密Url字符串,C#对Url进行处理,传递Url的更多相关文章
- Java & PHP & Javascript 通用 RSA 加密 解密 (长字符串)
系统与系统的数据交互中,有些敏感数据是不能直接明文传输的,所以在发送数据之前要进行加密,在接收到数据时进行解密处理:然而由于系统与系统之间的开发语言不同. 本次需求是生成二维码是通过java生成,由p ...
- RSA 加密 解密 (长字符串) JAVA JS版本加解密
系统与系统的数据交互中,有些敏感数据是不能直接明文传输的,所以在发送数据之前要进行加密,在接收到数据时进行解密处理:然而由于系统与系统之间的开发语言不同. 本次需求是生成二维码是通过java生成,由p ...
- C#加密解密DES字符串<转>
using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptograph ...
- PHP加密解密字符串
项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理. 最常见的应用在用户登录以及一些AP ...
- url 字符串中的参数信息
/// <summary> /// 分析 url 字符串中的参数信息 /// </summary> /// <param nam ...
- PHP的加密解密字符串函数
程序中经常使用的PHP加密解密字符串函数 代码如下: /********************************************************************* 函数 ...
- php 加密解密字符串
/********************************************************************* 函数名称:encrypt 函数作用:加密解密字符串 使用方 ...
- node中转换URL字符串与查询字符串
一个完整的URL字符串中,从"?"(不包括?)到"#"(如果存在#)或者到该URL字符串结束(如果不存在#)的这一部分称为查询字符串. 可以使用Query St ...
- [PHP]加密解密函数
非常给力的authcode加密函数,Discuz!经典代码(带详解) function authcode($string, $operation = 'DECODE', $key = '', $exp ...
- 2个比较经典的PHP加密解密函数分享
项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理. 最常见的应用在用户登录以及一些AP ...
随机推荐
- MessageFormat理解,MessageFormat.format(Object obj)方法
MessageFormat.format(Object obj)方法主要用途为拼接message信息 用法: Object[] testArgs = {new String("张三" ...
- selectByExampleWithBLOBs-----搜索结果包含大字段类型----搜索结果包含大字段类型
http://www.jb51.net/article/121482.htm mybatis generator 使用方法教程(生成带注释的实体类)
- 学渣乱搞系列之Tarjan模板合集
学渣乱搞系列之Tarjan模板合集 by 狂徒归来 一.求强连通子图 #include <iostream> #include <cstdio> #include <cs ...
- Uva122 Trees on the level
Background Trees are fundamental in many branches of computer science. Current state-of-the art para ...
- 使用ajax,后台传回的数据处理
使用ajax,后台传到前台的是json数据,但这只是一个字符串的形式,需要进行转换为对象 转换后再使用$.each()方法进行遍历 使用alert(typeof msg) ; 可以查看msg的类型 ...
- Docker website
https://github.com/docker/labs/ (nguo123gmail Cooooos123!) Docker Tutorials and Labs At this time ...
- Linux command2
. CentOS 想查看哪个port开了,却提示命令无效 # yum -y install net-tools 2. How to install "wget" command i ...
- oracle 12c 初步操作
查看是否为cdb SQL> select name,cdb,open_mode,con_id from v$database; NAME CDB OPEN_MODE CON_ID ------- ...
- eclipse 安装egit插件
一.Eclipse上安装GIT插件EGit Eclipse的版本eclipse-java-helios-SR2-win32.zip(在Eclipse3.3版本找不到对应的 EGit插件,无法安装) E ...
- 1.求整数最大的连续0的个数 BinaryGap Find longest sequence of zeros in binary representation of an integer.
求整数最大的连续0的个数 A binary gap within a positive integer N is any maximal sequence of consecutive zeros t ...