CA2202, how to solve this case

后端 未结 12 1112
闹比i
闹比i 2020-11-22 08:18

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         


        
12条回答
  •  温柔的废话
    2020-11-22 08:34

    I used this kind of code that takes byte[] and return byte[] without using streams

    public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)
    {
      DES des = new DES();
      des.BlockSize = 128;
      des.Mode = CipherMode.CBC;
      des.Padding = PaddingMode.Zeros;
      des.IV = IV
      des.Key = key
      ICryptoTransform encryptor = des.CreateEncryptor();
    
      //and finaly operations on bytes[] insted of streams
      return encryptor.TransformFinalBlock(plaintextarray,0,plaintextarray.Length);
    }
    

    This way all you have to do is conversion from string to byte[] using encodings.

提交回复
热议问题