以下是一个使用C#解密AES Rijndael的示例代码:
using System;
using System.Security.Cryptography;
using System.Text;
public class AESDecryptor
{
public static string DecryptString(string cipherText, string key, string iv)
{
byte[] encryptedBytes = Convert.FromBase64String(cipherText);
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
byte[] ivBytes = Encoding.UTF8.GetBytes(iv);
string plaintext = null;
using (Aes aes = Aes.Create())
{
aes.Key = keyBytes;
aes.IV = ivBytes;
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using (var ms = new System.IO.MemoryStream(encryptedBytes))
{
using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
{
using (var sr = new System.IO.StreamReader(cs))
{
plaintext = sr.ReadToEnd();
}
}
}
}
return plaintext;
}
}
使用示例:
string encryptedText = "AesEncryptedText";
string key = "YourEncryptionKey";
string iv = "YourIV";
string decryptedText = AESDecryptor.DecryptString(encryptedText, key, iv);
Console.WriteLine(decryptedText);
请注意,您需要将 "AesEncryptedText" 替换为要解密的实际密文,将 "YourEncryptionKey" 替换为您的实际密钥,将 "YourIV" 替换为您的实际初始化向量。