码迷,mamicode.com
首页 > 编程语言 > 详细

unity3d 数据加/解密

时间:2014-11-11 12:20:32      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   for   数据   div   

unity3D项目中的c#脚本加解密方法。

1、加密

 1 /// <summary>
 2 
 3 /// 内容加密
 4 
 5 /// </summary>
 6 
 7 /// <param name="ContentInfo">要加密内容</param>
 8 
 9 /// <param name="strkey">key值</param>
10 
11 /// <returns></returns>
12 
13 public string encryptionContent(string ContentInfo,string strkey)
14 
15 {
16 
17 byte[] keyArray = UTF8Encoding.UTF8.GetBytes(strkey);
18 
19 RijndaelManaged encryption = new RijndaelManaged();
20 
21 encryption.Key = keyArray;
22 
23 encryption.Mode = CipherMode.ECB;
24 
25 encryption.Padding = PaddingMode.PKCS7;
26 
27 ICryptoTransform cTransform = encryption.CreateEncryptor();
28 
29 byte[] _EncryptArray = UTF8Encoding.UTF8.GetBytes(ContentInfo);
30 
31 byte[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, 0, _EncryptArray.Length);
32 
33 return Convert.ToBase64String(resultArray, 0, resultArray.Length);
34 
35 }

2、解密

 1 /// <summary>
 2 
 3 /// 内容解密
 4 
 5 /// </summary>
 6 
 7 /// <param name="encryptionContent">被加密内容</param>
 8 
 9 /// <param name="strkey">key值</param>
10 
11 /// <returns></returns>
12 
13 public string decipheringContent(string encryptionContent,string strkey)
14 
15 {
16 
17 byte[] keyArray = UTF8Encoding.UTF8.GetBytes(strkey);
18 
19 RijndaelManaged decipher = new RijndaelManaged();
20 
21 decipher.Key = keyArray;
22 
23 decipher.Mode = CipherMode.ECB;
24 
25 decipher.Padding = PaddingMode.PKCS7;
26 
27 ICryptoTransform cTransform = decipher.CreateDecryptor();
28 
29 byte[] _EncryptArray = Convert.FromBase64String(encryptionContent);
30 
31 byte[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, 0, _EncryptArray.Length);
32 
33 return UTF8Encoding.UTF8.GetString(resultArray);
34 
35 }

 

unity3d 数据加/解密

标签:style   blog   io   color   ar   sp   for   数据   div   

原文地址:http://www.cnblogs.com/atong/p/4088976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!