Can anybody tell me how to remove all CA2202 warnings from the following code?
public static byte[] Encrypt(string data, byte[] key, byte[] iv)
{
us
Off-topic but I would suggest you to use a different formatting technique for grouping using
s:
using (var memoryStream = new MemoryStream())
{
using (var cryptograph = new DESCryptoServiceProvider())
using (var encryptor = cryptograph.CreateEncryptor(key, iv))
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
using (var streamWriter = new StreamWriter(cryptoStream))
{
streamWriter.Write(data);
}
return memoryStream.ToArray();
}
I also advocate using var
s here to avoid repetitions of really long class names.
P.S. Thanks to @ShellShock for pointing out I can't omit braces for first using
as it would make memoryStream
in return
statement out of the scope.