当前位置:网站首页>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;}}边栏推荐
- 千万级别的表分页查询非常慢,怎么办?
- 经典二分法查找的进阶题目——LeetCode33 搜索旋转排序数组
- 关于Oracle RAC 11g重建磁盘组的问题
- 使用GBase 8c数据库的时候,遇到这种报错
- ShuffleNet v2网络结构复现(Pytorch版)
- 高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
- 使用单调栈解决接雨水问题——LeetCode 42 接雨水+单调栈说明
- YOLOv5应用轻量级通用上采样算子CARAFE
- The sorting algorithm including selection, bubble, and insertion
- 并查集介绍和基于并查集解决问题——LeetCode 952 按公因数计算最大组件大小
猜你喜欢

C Language Lectures from Scratch Part 6: Structure

ShuffleNet v2网络结构复现(Pytorch版)

图的基本概念

智能健身动作识别:PP-TinyPose打造AI虚拟健身教练!

2022-08-02 分析RK817 输出32k clock PMIC_32KOUT_WIFI给WiFi模块 clock 注册devm_clk_hw_register

LeetCode 97. 交错字符串

B站回应HR称“核心用户都是Loser”、求职者是“白嫖党”:已被劝退

MySQL 8.0.29 详细安装(windows zip版)

高等代数_证明_对称矩阵一定能够相似对角化
![[STM32] STM32F103 series name and package, memory](/img/01/073f970c8c05ad24f976b26790ba61.png)
[STM32] STM32F103 series name and package, memory
随机推荐
金仓数据库 KDTS 迁移工具使用指南 (4. BS 版使用说明)
布局管理器
【论文笔记】Dynamic Convolution: Attention over Convolution Kernels
通过GBase 8c Platform安装数据库集群时报错
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?
【虚幻引擎UE】UE5实现WEB和UE通讯思路
Distributed Computing Experiment 1 Load Balancing
金仓数据库KingbaseES客户端编程接口指南-JDBC(10. JDBC 读写分离最佳实践)
sql在字段重复时 对某个字段根据最新时间取数
实现加载驱动、得到数据库对象、关闭资源的代码复用,将代码提取到相应的工具包里边。优化程序
推荐几种可以直接翻译PDF英文文献的方法
redis---分布式锁存在的问题及解决方案(Redisson)
「PHP基础知识」转换数据类型
金仓数据库 KDTS 迁移工具使用指南 (5. SHELL版使用说明)
8.2学习记录
Libpq 是否支持读写分离配置
为什么手动启动GBase 8c数据库中GTM节点,起不来。显示“Run cmd failed:scp: /tmp/gtm_gtm1.server: Permission denied”
【Attention】Dual Attention(DANet) & Fully Attention(FLA)
inject() can only be used inside setup() or functional components.
微信消息从发送到接收,经历了什么?如何防止丢包