49,935
社区成员




public static string AESDecrypt(string cipherString, string str)
{
if (string.IsNullOrEmpty(cipherString))
return string.Empty;
byte[] cipherText = Convert.FromBase64String(cipherString);
int length = cipherText.Length;
SymmetricAlgorithm des = Rijndael.Create();
des.Key = Convert.FromBase64String(str);
byte[] iv = new byte[16];
Buffer.BlockCopy(cipherText, 0, iv, 0, 16);
des.IV = iv;
byte[] decryptBytes = new byte[length - 16];
byte[] passwdText = new byte[length - 16];
Buffer.BlockCopy(cipherText, 16, passwdText, 0, length - 16);
using (MemoryStream ms = new MemoryStream(passwdText))
{
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read))
{
cs.Read(decryptBytes, 0, decryptBytes.Length);
cs.Close();
ms.Close();
}
}
return Encoding.UTF8.GetString(decryptBytes);
}