我无法理解这些代码分析警告的解决方案。
这是代码:
public static string Crypt(string s_Data, string s_Password, bool b_Encrypt)
{
byte[] u8_Salt = new byte[] { ... };
PasswordDeriveBytes i_Pass = new PasswordDeriveBytes(s_Password, u8_Salt);
Rijndael i_Alg = Rijndael.Create();
i_Alg.Key = i_Pass.GetBytes(32);
i_Alg.IV = i_Pass.GetBytes(16);
ICryptoTransform i_Trans = (b_Encrypt) ? i_Alg.CreateEncryptor() : i_Alg.CreateDecryptor();
MemoryStream i_Mem = new MemoryStream();
CryptoStream i_Crypt = new CryptoStream(i_Mem, i_Trans, CryptoStreamMode.Write);
byte[] u8_Data;
if (b_Encrypt)
u8_Data = Encoding.Unicode.GetBytes(s_Data);
else
u8_Data = Convert.FromBase64String(s_Data);
try
{
i_Crypt.Write(u8_Data, 0, u8_Data.Length);
i_Crypt.Close();
if (b_Encrypt)
return Convert.ToBase64String(i_Mem.ToArray());
else
return Encoding.Unicode.GetString(i_Mem.ToArray());
}
catch
{
return null;
}
finally
{
i_Crypt.Close();
}
}
i_Crypt.Close()上出现错误;称呼。我可以看到我的代码中有两次调用。
错误: