当前位置:网站首页>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;
}
}
}
边栏推荐
- Biscuits (examination version)
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- Postman管理测试用例
- 图数据库ONgDB Release v-1.0.3
- Summary of redis AOF and RDB knowledge points
- nacos-高可用seata之TC搭建(02)
- Review of double pointer problems
- MySQL if and ifnull use
- 2021RoboCom机器人开发者大赛(初赛)
- SQL injection vulnerability (MSSQL injection)
猜你喜欢

Leetcode dynamic planning day 16

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

GAMES202-WebGL中shader的编译和连接(了解向)

Compilation and connection of shader in games202 webgl (learn from)

RT thread analysis - object container implementation and function

Acwing week 58

CUDA11.1在线安装

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

Introduction of several RS485 isolated communication schemes

比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
随机推荐
Microblogging hot search stock selection strategy
Oracle query table index, unique constraint, field
Compilation and connection of shader in games202 webgl (learn from)
Postman test report
Redis has four methods for checking big keys, which are necessary for optimization
几种RS485隔离通讯的方案介绍
内核判断i2c地址上是否挂载外设
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
EditorUtility.SetDirty在Untiy中的作用以及应用
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
MySQL time processing
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
[数学建模] 微分方程--捕鱼业的持续发展
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
Lepton 无损压缩原理及性能分析
Ora-01779: the column corresponding to the non key value saving table cannot be modified
RT thread analysis log system RT_ Kprintf analysis
Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
Postman测试报告