当前位置:网站首页>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;}}
边栏推荐
- 24.循环神经网络RNN
- IntelliJ新建一个类或者包的快捷键是什么?
- 金仓数据库 KDTS 迁移工具使用指南 (5. SHELL版使用说明)
- redis---分布式锁存在的问题及解决方案(Redisson)
- inject() can only be used inside setup() or functional components.
- RT-Thread Studio学习(十二)W25Q128(SPI)的读写
- 给Unity Behavior Designer(Unity行为树) 的Can See Object 画圆锥辅助图
- 高等代数_证明_对称矩阵属于不同特征值的特征向量正交
- Convert callback function to Flow
- binder通信实现
猜你喜欢
随机推荐
unittest使用简述
【STM32】STM32F103系列名称与封装、内存
千万级别的表分页查询非常慢,怎么办?
关于常用状态码4XX提示错误
发现WRH几个表被锁了,怎么办?
1161. Maximum Level Sum of a Binary Tree
金仓数据库 KDTS 迁移工具使用指南 (7. 部署常见问题)
【论文笔记】Dynamic Convolution: Attention over Convolution Kernels
布局管理器
【UE虚幻引擎】UE5实现动态导航样条线绘制
【Attention】Dual Attention(DANet) & Fully Attention(FLA)
使用单调栈解决接雨水问题——LeetCode 42 接雨水+单调栈说明
JNI学习1.环境配置与简单函数实现
2022的七夕,奉上7个精美的表白代码,同时教大家改源码快速自用
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?
给Unity Behavior Designer(Unity行为树) 的Can See Object 画圆锥辅助图
经典动态规划问题的递归实现方法——LeetCode39 组合总和
新特性解读 | MySQL 8.0 在线调整 REDO
Linux Redis cache avalanche, breakdown, penetration
如何设计一个注册中心