当前位置:网站首页>Unity3D data encryption
Unity3D data encryption
2022-08-04 08:33:00 【overgrown valley】
Encryption mainly uses the AEC encryption method and the CBC encryption mode.AES (Advanced Encryption Standard) encryption is the next-generation encryption algorithm standard with high speed and high security level.In .NET, one implementation of the current AES standard is the Rijndael algorithm.
The code is as follows:
using System;using System.IO;using System.Security.Cryptography;using System.Text;public class EncryptTools{private static string AES_KEY = "abc123456789asfd"; // can be 16/24/32 bitprivate static string AES_IV = "gsf4jvkyhye57k8O";/// /// AES encryption (Advanced Encryption Standard, is the next generation encryption algorithm standard, fast speed, high security level, one implementation of the current AES standard is Rijndael algorithm)/// /// ciphertext to be encryptedpublic static string AESEncrypt(string EncryptString){return Encoding.UTF8.GetString(AESEncrypt(Encoding.UTF8.GetBytes(EncryptString)));}/// /// AES encryption (Advanced Encryption Standard, is the next generation encryption algorithm standard, fast speed, high security level, one implementation of the current AES standard is Rijndael algorithm)/// /// ciphertext to be encryptedpublic static byte[] AESEncrypt(byte[] contentBytes){if (contentBytes.Length == 0) { return contentBytes; }byte[] resultBytes;try{byte[] keyBytes = Encoding.UTF8.GetBytes(AES_KEY);byte[] iv = Encoding.UTF8.GetBytes(AES_IV);RijndaelManaged rm = new RijndaelManaged();rm.Key = keyBytes;rm.IV = iv;rm.Mode = CipherMode.CBC;rm.Padding = PaddingMode.PKCS7;ICryptoTransform ict = rm.CreateEncryptor();resultBytes = ict.TransformFinalBlock(contentBytes, 0, contentBytes.Length);}catch (IOException ex) { throw ex; }catch (CryptographicException ex) { throw ex; }catch (ArgumentException ex) { throw ex; }catch (Exception ex) { throw ex; }return resultBytes;}/// /// AES decryption (Advanced Encryption Standard, is the next-generation encryption algorithm standard, with high speed and high security level, one implementation of the current AES standard is Rijndael algorithm)/// /// ciphertext to be decryptedpublic static string AESDecrypt(string DecryptString){return Encoding.UTF8.GetString(AESDecrypt(Convert.FromBase64String(DecryptString)));}/// /// AES decryption (Advanced Encryption Standard, is the next-generation encryption algorithm standard, with high speed and high security level, one implementation of the current AES standard is Rijndael algorithm)/// /// ciphertext to be decryptedpublic static byte[] AESDecrypt(byte[] contentBytes){if (contentBytes.Length == 0) { return contentBytes; }byte[] resultBytes;try{byte[] keyBytes = Encoding.UTF8.GetBytes(AES_KEY);byte[] iv = Encoding.UTF8.GetBytes(AES_IV);RijndaelManaged rm = new RijndaelManaged();rm.Key = keyBytes;rm.IV = iv;rm.Mode = CipherMode.CBC;rm.Padding = PaddingMode.PKCS7;ICryptoTransform ict = rm.CreateDecryptor();resultBytes = ict.TransformFinalBlock(contentBytes, 0, contentBytes.Length);}catch (IOException ex) { throw ex; }catch (CryptographicException ex) { throw ex; }catch (ArgumentException ex) { throw ex; }catch (Exception ex) { throw ex; }return resultBytes;}}
边栏推荐
- inject() can only be used inside setup() or functional components.
- C Language Lectures from Scratch Part 6: Structure
- Libpq 是否支持读写分离配置
- 沃尔玛、阿里国际该如何做测评自养号?
- 「PHP基础知识」转换数据类型
- dalle:zero-shot text-to-image generation
- 【UE虚幻引擎】UE5实现动态导航样条线绘制
- How to write patents are more likely to pass?
- Thread类的基本使用。
- 高等代数_证明_对称矩阵属于不同特征值的特征向量正交
猜你喜欢
并查集介绍和基于并查集解决问题——LeetCode 952 按公因数计算最大组件大小
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
预测性维护学习之路
binder通信实现
【虚幻引擎UE】UE5实现WEB和UE通讯思路
经典二分法查找的进阶题目——LeetCode33 搜索旋转排序数组
从零开始的tensorflow小白使用指北
[STM32] STM32F103 series name and package, memory
24.循环神经网络RNN
[NOI Simulation Competition] Paper Tiger Game (Game Theory SG Function, Long Chain Division)
随机推荐
安装GBase 8c数据库的时候,报错显示“Resource:gbase8c already in use”,这怎么处理呢?
【虚幻引擎UE】UE5实现WEB和UE通讯思路
binder通信实现
大佬们,mysql里text类型的字段,FlinkCDC需要特殊处理吗 就像处理bigint uns
线程的状态
关于Oracle RAC 11g重建磁盘组的问题
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
华为设备配置VRRP与NQA联动监视上行链路
JNI学习1.环境配置与简单函数实现
Mysql insert on duplicate key 死锁问题定位与解决
LeetCode 135. 分发糖果
经典动态规划问题的递归实现方法——LeetCode39 组合总和
dalle:zero-shot text-to-image generation
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?
Linux之Redis 缓存雪崩,击穿,穿透
此时已莺飞草长,愿世间美好与你环环相扣
int *p = &a、p = &a、*p = a的正确理解
【虚幻引擎UE】UE5基于Gltf加载插件实现gltf格式骨骼动画在线/本地导入和切换
【STM32】STM32F103系列名称与封装、内存
JMeter 常用的几种断言方法,你会几种呢?