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加密 解密的更多相关文章

  1. iOS 3DES加密解密(一行代码搞定)

    3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...

  2. 简进祥==iOS 3DES加密解密

    3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...

  3. C# Java 3DES加密解密 扩展及修正\0 问题

    注: C#已亲测及做扩展, Java 部分未做验证 /// <summary> /// 3DES加密解密 /// ------------------------------------- ...

  4. 【推荐】JAVA基础◆浅谈3DES加密解密

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  5. 3DES加密解密

    C#3DES加密解密,JAVA.PHP可用 using System; using System.Security.Cryptography; using System.Text; namespace ...

  6. Des与3Des加密解密

    /// <summary> /// Des和3Des算法 /// </summary> public class Des { /// <summary> /// D ...

  7. C#的3DES加密解密算法

    C#类如下: using System; using System.Collections.Generic; using System.Text; using System.Security.Cryp ...

  8. JAVA和C# 3DES加密解密

    最近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题, 下面分享一下, 这里的KEY采用Base64编码,便用分发,因为Java的B ...

  9. JAVA安卓和C# 3DES加密解密的兼容性问题(2013年8月修改版)

    近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题, 下面分享一下, 这里的KEY采用Base64编码,便用分发,因为Java的By ...

  10. Java中3DES加密解密与其他语言(如C/C++)通信

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

随机推荐

  1. Java基础知识强化之集合框架笔记10:Collection集合使用的步骤

    集合使用的步骤: (1)创建集合对象 (2)创建元素对象 (3)把元素添加到集合 (4)遍历集合:       • 通过集合对象获取迭代器对象 • 通过迭代器对象的hasnext()方法判断是否有元素 ...

  2. Linux磁盘管理:lvcreate 常用命令

    查看当前LV及PV信息: [root@rusky ~]# hostnamectl Static hostname: localhost.localdomain Transient hostname: ...

  3. codevs 3332 数列 (矩阵乘法)

    /* 裸地矩阵乘法 矩阵很好想的 1 1 0 0 0 1 1 0 0 */ #include<iostream> #include<cstring> #include<c ...

  4. codevs1690开关灯

    #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #def ...

  5. datagrid加下拉列表dropdownlist

    datagrid中代码: <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAli ...

  6. C#中创建线程,创建带参数的线程

    线程操作主要用到Thread类,他是定义在System.Threading.dll下.使用时需要添加这一个引用.该类提供给我们四个重载的构造函 构造函数定义: 无参数委托 [SecuritySafeC ...

  7. sql语句分页代码

    SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO alter proc sp_SelectInfomationByKeyWord--创建一个存储过程 - ...

  8. SQL Database学习笔记

    1. linux下快速安装MariaDB: MariaDB 是 一个采用 Maria 存储引擎的  MySQL  分支版本,是由原来 MySQL 的作者 Michael Widenius 创办的公司所 ...

  9. 各种开源协议介绍 BSD、Apache Licence、GPL V2 、GPL V3 、LGPL、MIT

    现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的开源协议目前有58种(http://www.opensource.org/licenses /alphabeti ...

  10. 让 IE6/7/8 也支持HTML5标签的方式

    方式一:引入Google的HTML5.js线上文件 <!–[if lt IE9]> <script src="http://html5shiv.googlecode.com ...