C# 实现3Des加密 解密
3Des对每个数据块进行了三次的DES加密算法,是DES的一个更安全的变形。比起最初的DES,3DES更为安全。
都是感觉一目了然的摘过来。
下面是加密解密的源码。ECB模式的。
public class _3DESEncrypt
{ public static string Encrypt3DES(string a_strString, string a_strKey)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(a_strKey, "md5").Substring(, ));
DES.Mode = CipherMode.ECB;
ICryptoTransform DESEncrypt = DES.CreateEncryptor();
byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(a_strString);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, , Buffer.Length));
} public static string Decrypt3DES(string a_strString, string a_strKey)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(a_strKey, "md5").Substring(, ));
DES.Mode = CipherMode.ECB;
DES.Padding = System.Security.Cryptography.PaddingMode.PKCS7;
ICryptoTransform DESDecrypt = DES.CreateDecryptor();
string result = "";
try
{
byte[] Buffer = Convert.FromBase64String(a_strString); result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, , Buffer.Length)); //MemoryStream msDecrypt = new MemoryStream(Buffer);
//CryptoStream csDecrypt = new CryptoStream(msDecrypt,
// DES.CreateDecryptor(DES.Key, DES.IV),
// CryptoStreamMode.Read); //// Create buffer to hold the decrypted data.
//byte[] fromEncrypt = new byte[Buffer.Length]; //// Read the decrypted data out of the crypto stream
//// and place it into the temporary buffer.
//csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
//result = System.Text.Encoding.Default.GetString(fromEncrypt);
}
catch (Exception e)
{
}
return result; }
}
里面加解密都是在DES的基础上实现、区别在于3Des的Key值是24位、DES而是8位。
DES的加密解密源码:http://www.cnblogs.com/tainshi/p/3501258.html
对于3DES算法的CBC模式、我是新人存在迷惑、解密出来的数据有乱码现象。大大们有这方面有关的文章、推荐给我喽。
C# 实现3Des加密 解密的更多相关文章
- iOS 3DES加密解密(一行代码搞定)
3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...
- 简进祥==iOS 3DES加密解密
3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...
- C# Java 3DES加密解密 扩展及修正\0 问题
注: C#已亲测及做扩展, Java 部分未做验证 /// <summary> /// 3DES加密解密 /// ------------------------------------- ...
- 【推荐】JAVA基础◆浅谈3DES加密解密
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 3DES加密解密
C#3DES加密解密,JAVA.PHP可用 using System; using System.Security.Cryptography; using System.Text; namespace ...
- Des与3Des加密解密
/// <summary> /// Des和3Des算法 /// </summary> public class Des { /// <summary> /// D ...
- C#的3DES加密解密算法
C#类如下: using System; using System.Collections.Generic; using System.Text; using System.Security.Cryp ...
- JAVA和C# 3DES加密解密
最近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题, 下面分享一下, 这里的KEY采用Base64编码,便用分发,因为Java的B ...
- JAVA安卓和C# 3DES加密解密的兼容性问题(2013年8月修改版)
近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题, 下面分享一下, 这里的KEY采用Base64编码,便用分发,因为Java的By ...
- Java中3DES加密解密与其他语言(如C/C++)通信
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
随机推荐
- DTD简单使用
DTD:Document Type Definition DTD是一种简单的XML约束模式语言 DTD文档必须以utf-8或unicode编码 注释方式与HTML.XML文档相同 DTD文档的引用:紧 ...
- Android系统移植与驱动开发--第四章
第四章 源代码的下载和编译 一个android内核相当于4G,而一个Linux内个只有几百M,Linux内核相对于android内核来说实在是小巫见大巫.了解android源代码不一定要详细了解,只去 ...
- HDU 4462(暴力枚举)
因为题目当中的k比较小k <= 10,所以可以直接枚举,题目里面由两个trick, 一个是如果每个点都可以放稻草人的话,那么答案是0, 另外一个就是如果可以放稻草人的点不用被照到.知道了这两个基 ...
- 什么是AAC音频格式 AAC-LC 和 AAC-HE的区别是什么
Advanced Audio Coding(高级音频解码),是一种由MPEG-4标准定义的有损音频压缩格式,由Fraunhofer发展,Dolby, Sony和AT&T是主要的贡献者. 在使用 ...
- poj 1201 Interval (查分约束)
/* 数组开大保平安. 查分约束: 输入的时候维护st和end 设每个点取元素di个 维护元素个数前缀和s Sbi-Sai-1>=ci 即:建立一条从ai-1到bi的边 权值为ci 表示ai到b ...
- phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置
下载了个phpmyadmin最新版本的,始终显示这样的内容,求助.如何解决哈?>缺少 mysqli 扩展.请检查 PHP 配置. <a href="Documentation.h ...
- xls和xlsx
xls XLS 就是 Microsoft Excel 工作表,是一种非常常用的电子表格格式.xls文件可以使用Microsoft Excel打开,另外微软为那些没有安装Excel的用户开发了专门的 ...
- js bind
1.作用 函数的bind方法用于将函数体内的this绑定到某个对象,然后返回一个新函数. //bind 相比于call apply this 都等于 obj; bind是产生一个新的函数 不执 ...
- POJ2566-Bound Found (尺取法)
POJ2566-Bound Found 题目大意:给出一段长度为n的数列,数列中的元素有正有负,求一段连续的区间,使得该区间的和的绝对值最接近给定的值 尺取法一般适用于对一段连续的区间的和进行处理的情 ...
- MESH
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_meshtest.html A class that allows c ...