public static System.Security.SecureString Decrypt128StringSecure(Stream Data, byte[] Key)
{
AesCryptoServiceProvider AES = null;
CryptoStream CS = null;
StreamReader DS = null;
try
{
//Get the IV and length corrected Key.
KeyData KeyData = GenerateKeyIV128(Key);
//Create the AES crytpograhy object.
AES = new AesCryptoServiceProvider { BlockSize = 128, KeySize = 128, Key = KeyData.Key, IV = KeyData.IV, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 };
CS = new CryptoStream(Data, AES.CreateDecryptor(), CryptoStreamMode.Read);
DS = new StreamReader(CS);
var ss = new System.Security.SecureString();
while (DS.EndOfStream == false)
ss.AppendChar(Convert.ToChar(DS.Read()));
ss.MakeReadOnly();
return ss;
}
finally
{
if (AES != null) AES.Clear();
if (CS != null) CS.Dispose();
if (DS != null) DS.Dispose();
}
}