Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HPF ortify scan reported Privacy Violation issue at below line of code.
C#
csEncrypt.Write(buffer, 0, read);



complete code

C#
public void Encrypt(Stream data, Stream output, byte[] key = null, byte[] iv = null)
              {
                     if (data == null) { throw new ArgumentNullException("data"); }
                     if (data.Length <= 0) { throw new ArgumentException("Empty Data", "data"); }
                     if (output == null) { throw new ArgumentNullException("output"); }
 
                     using (var rijAlg = new RijndaelManaged())
                     using (var encryptor = rijAlg.CreateEncryptor(key ?? GetDefaultKey(), iv ?? GetDefaultIV()))
                     using (var csEncrypt = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
                     {
                           var buffer = new byte[bufferLength];
                           var read = data.Read(buffer, 0, bufferLength);
                           while (read != 0)
                           {
                                  csEncrypt.Write(buffer, 0, read);
                                  read = data.Read(buffer, 0, bufferLength);
                           }
                           csEncrypt.Close();
                     }
              }




I wanted to know best way to encrypt data and avoid privacy violation issue.

What I have tried:

HP Fortify scan says:
C#
The method Encrypt() mishandles confidential information, which can compromise user privacy and is often illegal.Mishandling private information, such as customer passwords or social security numbers, can compromise user privacy and is often illegal.
Posted
Comments
F-ES Sitecore 19-Oct-16 5:46am    
https://cwe.mitre.org/data/definitions/359.html

The issue is more likely to be with what you do with the stream after it has been encrypted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900