国产丰满大乳无码免费播放_久草一级毛片_国产av黄色一区二区_亚洲一级 片内射欧美乱强上司_制服丝袜亚洲日韩中文字幕欧美_亚洲av中文小島_国产精品无码久久av嫩草下载_91视频黄片软件APP大全

XML|HTML|TXT
您當前位置: 軟件開發>> 新利在線娛樂>> 軟件開發技術>> 瀏覽文章

C# 實現3Des加密 解密

3Des對每個數據塊進行了三次的DES加密算法,是DES的一個更安全的變形。比起最初的DES,3DES更為安全。

都是感覺一目了然的摘過來。

下面是加密解密的源碼。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的基礎上實現、區別在于3Des的Key值是24位、DES而是8位。


手機:18678812288 E-Mail:1069706080@qq.com
地址:山東省濟南市舜耕路泉城公園東門園內向北50米 魯ICP備07011972號 版權所有2008-2013 新利體育18
Baidu