Search code examples
encryptionaesrijndaelmanaged.net-4.7

Why AesManaged.FeedbackSizeValue = 8 when AesManaged.FeedbackSize = 128


I wish to explicitly set the encryption parameters (as read from .NET 4.7 defaults) so as to avoid decryption difficulties later down the line when future framework versions implement different defaults.

Why is it that after manually setting the feedback FeedbackSize, the FeedbackSizeValue doesn't change ?

AesManaged aes = new AesManaged();
aes.Mode = CipherMode.CBC;
aes.KeySize = 256;
aes.Padding = PaddingMode.PKCS7;
aes.BlockSize = 128;
aes.FeedbackSize = aes.BlockSize;

Here is the aes object, see the FeedbackSizeValue 8

-       aes {System.Security.Cryptography.AesManaged}   System.Security.Cryptography.AesManaged

-       aes {System.Security.Cryptography.AesManaged}   System.Security.Cryptography.AesManaged
        BlockSize   128 int
        BlockSizeValue  128 int
        FeedbackSize    128 int
        FeedbackSizeValue   8   int
+       IV  {byte[16]}  byte[]
        IVValue null    byte[]
+       Key {byte[32]}  byte[]
        KeySize 256 int
        KeySizeValue    256 int
        KeyValue    null    byte[]
+       LegalBlockSizes {System.Security.Cryptography.KeySizes[1]}  System.Security.Cryptography.KeySizes[]
+       LegalBlockSizesValue    {System.Security.Cryptography.KeySizes[1]}  System.Security.Cryptography.KeySizes[]
+       LegalKeySizes   {System.Security.Cryptography.KeySizes[1]}  System.Security.Cryptography.KeySizes[]
+       LegalKeySizesValue  {System.Security.Cryptography.KeySizes[1]}  System.Security.Cryptography.KeySizes[]
        Mode    CBC System.Security.Cryptography.CipherMode
        ModeValue   CBC System.Security.Cryptography.CipherMode
        Padding PKCS7   System.Security.Cryptography.PaddingMode
        PaddingValue    PKCS7   System.Security.Cryptography.PaddingMode
+       m_rijndael  {System.Security.Cryptography.RijndaelManaged}  System.Security.Cryptography.RijndaelManaged
+       Static members      

Solution

  • CBC mode does not have a feedback size. See CBC mode:

    DCBC mode Graphic from Wikipedia

    Also there is no need to specify the block size (aes.BlockSize = 128;), AES only has one block size. Rijndael does support several block sizes and it is necessary to specify a block size of 128-bits to essentially be AES. While many Rijndael implementation default to a block size of 128-bits it is always better to fully specify parameters.