Home >Backend Development >C++ >How Can I Encrypt and Decrypt Data Using AES in C#?
Use C# to encrypt AES
Advanced Encryption Standard (AES) is a powerful group password that is widely used for data encryption. In C#, the class provides 128 -bit encryption AES implementation.
RijndaelManaged
code example
RijndaelManaged
<code class="language-csharp">using System; using System.Security.Cryptography; namespace AES加密 { class Program { static void Main(string[] args) { // 要加密的原始数据 string originalText = "这是要加密的数据"; // 生成密钥和初始化向量 (IV) using (RijndaelManaged rijndaelManaged = new RijndaelManaged()) { rijndaelManaged.GenerateKey(); rijndaelManaged.GenerateIV(); // 加密数据 byte[] encryptedText = rijndaelManaged.EncryptStringToBytes(originalText, rijndaelManaged.Key, rijndaelManaged.IV); // 解密数据 string decryptedText = rijndaelManaged.DecryptStringFromBytes(encryptedText, rijndaelManaged.Key, rijndaelManaged.IV); // 显示原始数据和解密数据 Console.WriteLine("原始文本: " + originalText); Console.WriteLine("加密文本: " + Convert.ToBase64String(encryptedText)); Console.WriteLine("解密文本: " + decryptedText); } } } }</code>and
methods provide auxiliary functions using specified keys and IV encryption and unlieving string. The statement is added to ensure that the EncryptStringToBytes
object is correctly released. DecryptStringFromBytes
using
Note:
RijndaelManaged
The above is the detailed content of How Can I Encrypt and Decrypt Data Using AES in C#?. For more information, please follow other related articles on the PHP Chinese website!