当前位置:网站首页>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;
}
}
}
边栏推荐
- 驱动开发——第一个HelloDDK
- [NOIP2008 提高组] 笨小猴
- Fiddler installed the certificate, or prompted that the certificate is invalid
- Programmers' position in the Internet industry | daily anecdotes
- ISP learning (2)
- MySQL time processing
- acwing周赛58
- The underlying structure of five data types in redis
- Oracle query table index, unique constraint, field
- 程序员在互联网行业的地位 | 每日趣闻
猜你喜欢

What are the advantages of the industry private network over the public network? What specific requirements can be met?

IPv6 comprehensive experiment

【LeetCode】18、四数之和

JS quick start (II)

【OSPF 和 ISIS 在多路访问网络中对掩码的要求】

Introduction of several RS485 isolated communication schemes

F12 solve the problem that web pages cannot be copied

程序员在互联网行业的地位 | 每日趣闻

ISP learning (2)

SQL injection vulnerability (MSSQL injection)
随机推荐
关于imx8mp的es8316的芯片调试
Postman前置脚本-全局变量和环境变量
行业专网对比公网,优势在哪儿?能满足什么特定要求?
Yolov5 tensorrt acceleration
Postman assertion
Crazy God said redis notes
Talking about the type and function of lens filter
Hyperledger Fabric2. Some basic concepts of X (1)
Postman Association
MPLS experiment
你需要知道的 TCP 三次握手
MySQL if and ifnull use
Project manager, can you draw prototypes? Does the project manager need to do product design?
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
What are the advantages of the industry private network over the public network? What specific requirements can be met?
Drive development - the first helloddk
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
ISP learning (2)
【LeetCode】18、四数之和
几种RS485隔离通讯的方案介绍