当前位置:网站首页>C AES encrypts strings
C AES encrypts strings
2022-07-06 05:10:00 【Handsome_ shuai_】
C# AES Encrypt the string
public class AESHelper
{
/// <summary>
/// AES Encrypted key Must be 32 position
/// </summary>
public static string keyValue = "12345678123456781234567812345678";
/// <summary>
/// AES Algorithm encryption
/// </summary>
/// <param name="content"> Plaintext </param>
/// <param name="Key"> secret key </param>
/// <returns> Encrypted ciphertext </returns>
public static string Encrypt(string content, string Key)
{
try
{
byte[] keyBytes = Encoding.UTF8.GetBytes(Key);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyBytes;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] contentBytes = Encoding.UTF8.GetBytes(content);
byte[] resultBytes = cTransform.TransformFinalBlock(contentBytes, 0, contentBytes.Length);
string result = Convert.ToBase64String(resultBytes, 0, resultBytes.Length);
return result;
}
catch (Exception ex)
{
UnityEngine.Debug.LogError(" Encryption error :" + ex.ToString());
return null;
}
}
/// <summary>
/// AES Algorithm decryption
/// </summary>
/// <param name="content"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Decipher(string content, string key)
{
try
{
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
RijndaelManaged rm = new RijndaelManaged();
rm.Key = keyBytes;
rm.Mode = CipherMode.ECB;
rm.Padding = PaddingMode.PKCS7;
ICryptoTransform ict = rm.CreateDecryptor();
byte[] contentBytes = Convert.FromBase64String(content);
byte[] resultBytes = ict.TransformFinalBlock(contentBytes, 0, contentBytes.Length);
return Encoding.UTF8.GetString(resultBytes);
}
catch (Exception ex)
{
UnityEngine.Debug.LogError(" Decryption error :" + ex.ToString());
return null;
}
}
}
边栏推荐
- EditorUtility.SetDirty在Untiy中的作用以及应用
- 关于imx8mp的es8316的芯片调试
- Upload nestjs configuration files, configure the use of middleware and pipelines
- Extension of graph theory
- Oracle deletes duplicate data, leaving only one
- Golang -- TCP implements concurrency (server and client)
- 行业专网对比公网,优势在哪儿?能满足什么特定要求?
- Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
- C# AES对字符串进行加密
- [noip2009 popularization group] score line delimitation
猜你喜欢
Postman前置脚本-全局变量和环境变量
acwing周赛58
Golang -- TCP implements concurrency (server and client)
Postman pre script - global variables and environment variables
Postman manage test cases
Review of double pointer problems
F12 solve the problem that web pages cannot be copied
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Postman管理测试用例
GAMES202-WebGL中shader的编译和连接(了解向)
随机推荐
树莓派3.5寸屏幕白屏显示连接
Summary of redis AOF and RDB knowledge points
用StopWatch 统计代码耗时
Postman断言
Collection + interview questions
集合详解之 Collection + 面试题
MPLS experiment
Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
Summary of three log knowledge points of MySQL
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
2021RoboCom机器人开发者大赛(初赛)
驱动开发——HelloWDM驱动
Ora-01779: the column corresponding to the non key value saving table cannot be modified
GAMES202-WebGL中shader的编译和连接(了解向)
Extension of graph theory
Microblogging hot search stock selection strategy
nacos-高可用seata之TC搭建(02)
EditorUtility.SetDirty在Untiy中的作用以及应用
Yolov5 tensorrt acceleration