九九热这里直有精品,1区二区三区在线播放,玖玖爱在线观看资源,国产aⅴ综合网,午夜福利男女,日本亚洲欧美三级,日韩无码黄色导航,内射少妇13区,中文字幕高清网

您身邊的軟件定制專家--9年開(kāi)發(fā)經(jīng)驗(yàn)為您護(hù)航

18678812288
0531-88887250

C# 實(shí)現(xiàn)3Des加密 解密

文章作者:濟(jì)南軟件開(kāi)發(fā) 時(shí)間:2016年12月20日

3Des對(duì)每個(gè)數(shù)據(jù)塊進(jìn)行了三次的DES加密算法,是DES的一個(gè)更安全的變形。比起最初的DES,3DES更為安全。

 

都是感覺(jué)一目了然的摘過(guò)來(lái)。

 

下面是加密解密的源碼。ECB模式的。

 

 1 public class _3DESEncrypt

 2     {

 3 

 4         public static string Encrypt3DES(string a_strString, string a_strKey)

 5         {

 6             TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();

 7             DES.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(a_strKey, "md5").Substring(0, 24));

 8             DES.Mode = CipherMode.ECB;

 9             ICryptoTransform DESEncrypt = DES.CreateEncryptor();

10             byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(a_strString);

11             return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));

12         }

13 

14         public static string Decrypt3DES(string a_strString, string a_strKey)

15         {

16             TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();

17             DES.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(a_strKey, "md5").Substring(0, 24));

18             DES.Mode = CipherMode.ECB;

19             DES.Padding = System.Security.Cryptography.PaddingMode.PKCS7;

20             ICryptoTransform DESDecrypt = DES.CreateDecryptor();

21             string result = "";

22             try

23             {

24                 byte[] Buffer = Convert.FromBase64String(a_strString);

25 

26                 result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));

27 

28                 //MemoryStream msDecrypt = new MemoryStream(Buffer);

29                 //CryptoStream csDecrypt = new CryptoStream(msDecrypt,

30                 //       DES.CreateDecryptor(DES.Key, DES.IV),

31                 //       CryptoStreamMode.Read);

32 

33                 //// Create buffer to hold the decrypted data.

34                 //byte[] fromEncrypt = new byte[Buffer.Length];

35 

36                 //// Read the decrypted data out of the crypto stream

37                 //// and place it into the temporary buffer.

38                 //csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);

39                 //result = System.Text.Encoding.Default.GetString(fromEncrypt);

40             }

41             catch (Exception e)

42             {

43             }

44             return result;

45 

46         }

47     }

 

里面加解密都是在DES的基礎(chǔ)上實(shí)現(xiàn)、區(qū)別在于3Des的Key值是24位、DES而是8位。


想要了解更多詳情歡迎來(lái)電咨詢18678812288
登陸網(wǎng)址:m.h6244.cn。
聯(lián)系人:王經(jīng)理。

屏山县| 乌鲁木齐市| 伊金霍洛旗| 兴安县| 醴陵市| 开远市| 娄烦县| 青州市| 夏河县| 阿图什市| 博客| 龙胜| 昂仁县| 萝北县| 宁蒗| 当涂县| 乌鲁木齐市| 中方县| 铜山县| 崇州市| 安丘市| 会东县| 周至县| 民乐县| 通山县| 井陉县| 平舆县| 康保县| 南澳县| 承德县| 鸡东县| 洪泽县| 连南| 西昌市| 松溪县| 安图县| 甘谷县| 和静县| 金昌市| 阜康市| 师宗县|