当前位置:网站首页>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;}}边栏推荐
猜你喜欢

【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解

关于#sql#的问题:后面换了一个数据库里面的数据就不能跑了

csdn图片去水印 | 其他方法无效时的解决方案

GIS数据与CAD数据间带属性字段互相转换还原工具,解决ArcGIS等软件进行GIS数据转CAD数据无法保留属性字段问题

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

binder通信实现

ShuffleNet v2 network structure reproduction (Pytorch version)

【论文笔记】Understanding Long Programming Languages with Structure-Aware Sparse Attention

【电脑录制屏】如何使用bandicam录游戏 设置图文教程

从零开始的tensorflow小白使用指北
随机推荐
Yolov5更换主干网络之《旷视轻量化卷积神经网络ShuffleNetv2》
int *p = &a、p = &a、*p = a的正确理解
dalle:zero-shot text-to-image generation
Typora_Markdown_图片标题(题注)
高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
DWB主题事实及ST数据应用层构建,220803,,
大佬们,mysql里text类型的字段,FlinkCDC需要特殊处理吗 就像处理bigint uns
Convert callback function to Flow
MMDetection finetune
线程安全问题
【论文笔记】Delving into the Estimation Shift of Batch Normalization in a Network
关于常用状态码4XX提示错误
binder通信实现
新特性解读 | MySQL 8.0 在线调整 REDO
【NOI模拟赛】纸老虎博弈(博弈论SG函数,长链剖分)
js - the first letter that appears twice
[STM32] STM32F103 series name and package, memory
占位,稍后补上
Typora颜色公式代码大全
关于#sql#的问题:后面换了一个数据库里面的数据就不能跑了