当前位置:网站首页>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;}}
边栏推荐
猜你喜欢
The difference between character stream and byte stream
Implementation of redis distributed lock
LeetCode 97. 交错字符串
RT-Thread Studio学习(十一)IIC
MySQL 8.0.29 详细安装(windows zip版)
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
[STM32] STM32F103 series name and package, memory
字符流与字节流的区别
Distributed Computing MapReduce | Spark Experiment
【STM32】STM32F103系列名称与封装、内存
随机推荐
此时已莺飞草长,愿世间美好与你环环相扣
在GBase 8c数据库后台,使用什么样的命令来对gtm、dn节点进行主备切换的操作?
leetcode 22.7.31(1)两数之和 (2)整数除法
关于Oracle RAC 11g重建磁盘组的问题
高等代数_证明_幂等矩阵一定能够相似对角化
unity3d-Animation&&Animator接口(基本使用)
金仓数据库KingbaseES客户端编程接口指南-JDBC(9. JDBC 读写分离)
关于常用状态码4XX提示错误
设计信息录入界面,完成人员基本信息的录入工作,
技术实现 | 图像检索及其在淘宝的应用
沃尔玛、阿里国际该如何做测评自养号?
JMeter 常用的几种断言方法,你会几种呢?
华为设备配置VRRP与路由联动监视上行链路
RT-Thread Studio学习(十一)IIC
C Language Lectures from Scratch Part 6: Structure
高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
微信消息从发送到接收,经历了什么?如何防止丢包
js - the first letter that appears twice
async - await
小程序如何使用订阅消息(PHP代码+小程序js代码)