3des用法示例,已测试
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Text;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
// The length of Encryptionstring should be 24 byte and not be a weak key
private string EncryptionString = "v3VC7LfCq6IL5KgIglqZrQ1b";
// The length of initialization vector should be 8 byte
private static Byte[] EncryptionIV = Encoding.Default.GetBytes("jaaaaaaa");
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 加密数据
/// </summary>
/// <param name="SourceData"></param>
/// <returns></returns>
public byte[] EncryptionByteData(byte[] SourceData)
{
byte[] returnData = null;
try
{
// Create TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider desProvider = new TripleDESCryptoServiceProvider();
// Set SecureKey and IV of desProvider
byte[] byteKey = Encoding.Default.GetBytes(EncryptionString);
desProvider.Key = byteKey;
desProvider.IV = EncryptionIV;
desProvider.Mode = CipherMode.ECB;
// A MemoryStream object
MemoryStream ms = new MemoryStream();
// Create Encryptor
ICryptoTransform encrypto = desProvider.CreateEncryptor();
// Create CryptoStream object
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
// Encrypt SourceData
cs.Write(SourceData, 0, SourceData.Length);
cs.FlushFinalBlock();
// Get Encryption result
returnData = ms.ToArray();
}
catch (Exception ex)
{
throw ex;
}
return returnData;
}
public byte[] DecryptionByteData(byte[] SourceData)
{
byte[] returnData = null;
try
{
// Create TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider desProvider = new TripleDESCryptoServiceProvider();
// Set SecureKey and IV of desProvider
byte[] byteKey = Encoding.Default.GetBytes(EncryptionString);
desProvider.Key = byteKey;
desProvider.IV = EncryptionIV;
desProvider.Mode = CipherMode.ECB;
// A MemoryStream object
MemoryStream ms = new MemoryStream();
// Create Decryptor
ICryptoTransform encrypto = desProvider.CreateDecryptor();
// Create CryptoStream object
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
// Decrypt SourceData
cs.Write(SourceData, 0, SourceData.Length);
cs.FlushFinalBlock();
// Get Decryption result
returnData = ms.ToArray();
}
catch (Exception ex)
{
throw ex;
}
return returnData;
}
/// <summary>
/// Encryption method for string
/// </summary>
/// <param name="SourceData">source data</param>
/// <returns>string</returns>
public string EncryptionStringData(string SourceData)
{
try
{
// Convert source data from string to byte array
byte[] SourData = Encoding.Default.GetBytes(SourceData);
// Encrypt byte array
byte[] retData = EncryptionByteData(SourData);
// Convert encryption result from byte array to Base64String
return Convert.ToBase64String(retData, 0, retData.Length);
}
catch (Exception ex)
{
throw ex;
}
}
public string DecryptionStringdata(string SourceData)
{
try
{
// Convert source data from Base64String to byte array
byte[] SourData = Convert.FromBase64String(SourceData);
// Decrypt byte array
byte[] retData = DecryptionByteData(SourData);
// Convert Decryption result from byte array to string
return Encoding.Default.GetString(retData, 0, retData.Length);
}
catch (Exception ex)
{
throw ex;
}
}
protected void btnEncryption_Click(object sender, EventArgs e)
{
string str = EncryptionStringData("在中国这样的情况下我们应在在一工人在一了人在和一人在在在在地地");
Response.Write(str);
}
protected void btnDeCrpty_Click(object sender, EventArgs e)
{
string str = "Flvuxnn/IcNQwLrL/HA8Jfq7Qwrk6uDmSuB4lwW4n2jf9e3gPy52K7BVpiyEStG0ajnLCRERRxdrkWani6K+aA== ";
str = DecryptionStringdata(str);
Response.Write(str);
}
}
3des用法示例,已测试的更多相关文章
- 腾讯云上PhantomJS用法示例
崔庆才 前言 大家有没有发现之前我们写的爬虫都有一个共性,就是只能爬取单纯的html代码,如果页面是JS渲染的该怎么办呢?如果我们单纯去分析一个个后台的请求,手动去摸索JS渲染的到的一些结果,那简直没 ...
- 腾讯云上Selenium用法示例
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者:崔庆才 前言 在上一节我们学习了PhantomJS 的基本用法,归根结底它是一个没有界面的浏览器,而且运 ...
- Linux find 用法示例
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...
- [转]Linux中find常见用法示例
Linux中find常见用法示例[转]·find path -option [ -print ] [ -exec -ok command ] {} \;find命令的参 ...
- Linux中 find 常见用法示例
Linux中find常见用法示例 #find path -option [ -print ] [ -exec -ok command ] {} \; #-print 将查找到的文件输出到标准输出 #- ...
- jQuery中$.fn的用法示例介绍
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效,下面有个不错的示例,喜欢的朋友可以参考下 如扩展$.fn.abc(),即$.fn.abc()是对jquery ...
- 关于 pgsql 数据库json几个函数用法的效率测试
关于 pgsql 数据库json几个函数用法的效率测试 关于pgsql 几个操作符的效率测试比较1. json::->> 和 ->> 测试方法:单次运行100次,运行10个单次 ...
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
转--http://www.2cto.com/kf/201402/277535.html 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版! 2014-02-11 ...
- oracle中to_date详细用法示例(oracle日期格式转换)
这篇文章主要介绍了oracle中to_date详细用法示例,包括期和字符转换函数用法.字符串和时间互转.求某天是星期几.两个日期间的天数.月份差等用法 TO_DATE格式(以时间:2007-11-02 ...
随机推荐
- Java课程设计—学生成绩管理系统
一. 团队名称.团队成员介绍(需要有照片) 团队名称:进击的712 团队成员 杨雪莹[组长] 201521123005 网络1511 林楚虹 201521123002 网络1511 董美凤 20152 ...
- 201521123037 《Java程序设计》第9周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. java异常继承架构 2. 书面作业 本次PTA作业题集异常 1. 常用异常 题目5-1 1.1 截图你的提交结果( ...
- Python可视化----------matplotlib.pylot
1 >>> import matplotlib.pyplot as plt 2 >>> plt.axis([0,5,0,20]) 3 [0, 5, 0, 20] 4 ...
- 框架基础:ajax设计方案(六)--- 全局配置、请求格式拓展和优化、请求二进制类型、浏览器错误搜集以及npm打包发布
距离上一次博客大概好多好多时间了,感觉再不搞点东西出来,感觉就废了的感觉.这段时间回老家学习驾照,修养,然后7月底来上海求职(面了4家,拿了3家office),然后入职同程旅游,项目赶进度等等一系列的 ...
- Maven 整合strut与Hibernate,获取不到Session
struts使用的是2.3.24 Hibernate使用的5.0.7 注意hebernate一定要在struts之前申明,不然容易出现500错误, <project xmlns="ht ...
- React——高阶组件
1.在React中higher-order component (HOC)是一种重用组件逻辑的高级技术.HOC不是React API中的一部分.HOC是一个函数,该函数接收一个组件并且返回一个新组件. ...
- struts标签与jstl标签互换
近期在做struts切换spring mvc时发现代码中使用了大量的struts标签,对常用的struts标签做了总结,首先需要引入 <%@ taglib prefix="c" ...
- Visual Studio + Qt开发环境搭建
1. 安装Visual Studio 2015 Visual Studio 2015下载地址如下,安装比较常规,不做介绍. Visual Studio Enterprise 2015 with Upd ...
- 51nod 1118 机器人走方格 解题思路:动态规划 & 1119 机器人走方格 V2 解题思路:根据杨辉三角转化问题为组合数和求逆元问题
51nod 1118 机器人走方格: 思路:这是一道简单题,很容易就看出用动态规划扫一遍就可以得到结果, 时间复杂度O(m*n).运算量1000*1000 = 1000000,很明显不会超时. 递推式 ...
- java数据库编程之嵌套子查询及exists的使用
第四章:高级查询(二) 4.1:exists和not exists子查询 4.1.1:exists子查询 用exists作为子查询的where条件 语法:select,,,,,,from 表名 w ...