I am trying to encrypt and decrypt my connection string. Below is the code used to encrypt. When I code underwent SSA Fortify
, I get the error as below.
xyz.cs stores sensitive data in an insecure manner, making it possible to extract the data via inspecting the heap.
public static int GetSaltSize(byte[] pBytes)
{
var key = new Rfc2898DeriveBytes(pBytes, pBytes, 1000);
byte[] ba = key.GetBytes(2);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ba.Length; i++)
{
sb.Append(Convert.ToInt32(ba[i]).ToString());
}
int saltSize = 0;
string s = sb.ToString(); // <--- insecure?
foreach (char c in s)
{
int intc = Convert.ToInt32(c.ToString());
saltSize = saltSize + intc;
}
return saltSize;
}
Please let me know if we can convert StringBuilder
to SecureString
or what can be the solution.