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 ...
随机推荐
- ★★★★[转载]Python学习笔记一:数据类型转换★★★★
一.int函数能够 (1)把符合数学格式的数字型字符串转换成整数 (2)把浮点数转换成整数,但是只是简单的取整,而非四舍五入. 举例: 1 aa = int("124&quo ...
- Java实现Windows平台下Ping的最佳方法
先上结论:通过调用系统自带的Ping命令来实现,使用exitValue()值来判断Ping的结果.按照惯例,0表示ok,1表示不通. private static void pingTest1() t ...
- 压缩空格的函数以及BCD码与ASCII相互转换函数
/**函数名:zip_space功能 :压缩空格的函数参数 : s 源字符串返回值: 0 成功**/ int zip_space(char *s){ int i,j; int len; ) { ; } ...
- 模拟实现一个ATM+购物商城程序
记得上次小编上传了一个购物车程序,这次呢稍微复杂一点,还是那句话,上传在这里不是为了炫耀什么,只是督促小编学习,如果大神有什么意见和建议,欢迎指导.(PS:本次主要参考学习为主,自己原创的很少) 要求 ...
- jquery ocupload一键上传文件应用
直接上栗子 这是官方文档栗子 var myUpload = $(element).upload({ name: 'file', action: '', enctype: 'multipart/form ...
- 再起航,我的学习笔记之JavaScript设计模式24(备忘录模式)
备忘录模式 概念介绍 备忘录模式(Memento): 在不破坏对象的封装性的前提下,在对象之外捕获并保存该对象内部的状态以便日后对象使用或者对象恢复到以前的某个状态. 简易分页 在一般情况下我们需要做 ...
- YYHS-NOIP2017Training0921-逆光
题目描述 有一束光/那瞬间/是什么痛得刺眼/你的视线是谅解/为什么舍不得熄灭/我逆着光却看见/那是泪光/那力量/我不想再去抵挡/面对希望/逆着光/感觉爱存在的地方/一直就在我身旁 Descriptio ...
- [UIKit学习]08.关于自定义控件
自定义控件 选用xib用自定义view代码与xib相关联 示例代码 + (instancetype)shopView { return [self shopViewWithShop:nil]; } + ...
- [UIKit学习]01.关于UIView,frame,bounds,center
UIView是Cocoa大多控件的父类,本身不带事件. UIView的常见用法 @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 ...
- 反射结合xml简单的模拟spring创建bean
框架最底层其实就是通过反射实现的,就像spring,当你配置各种各样的bean时都是以配置文件的形式配置的,你需要用到哪些bean就配哪些,spring容器就会根据你的需求去动态加载,这儿写一个简单的 ...