• unity3d 数据加/解密


    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 }
  • 相关阅读:
    apache 访问出现403 Forbidden
    linux下用Apache一个IP多个域名建虚拟主机
    利用xargs 可以一次性卸载到位
    linux安装包地址备忘
    ii7安装php
    基于jQuery的对象切换插件:soChange 1.5 (点击下载)
    phpMyAdmin 缺少 mysqli 扩展。请检查 PHP 配置
    Android中的自动朗读(TTS)
    Android中的手势
    Android中的SQLiteOpenHelper类
  • 原文地址:https://www.cnblogs.com/atong/p/4088976.html
Copyright © 2020-2023  润新知