Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Rijndael BlockSize vs GetBytes?

What's the difference between using BlockSize or GetBytes?

            var keyGen = new Rfc2898DeriveBytes(pass, 8)        
            var aes = Rijndael.Create(); //Rijndael
            aes.Padding = PaddingMode.PKCS7;
            aes.IV = keyGen.GetBytes(aes.BlockSize / 8);
            aes.Key = keyGen.GetBytes(aes.KeySize / 8);

  - VS -
            aes.IV = keyGen.GetBytes(16);
            aes.Key = keyGen.GetBytes(32);
ASKER CERTIFIED SOLUTION
Avatar of mlan
mlan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pointeman

ASKER

Okay, so BlockSize is measured in bits and / 8 converts to needed bytes for GetBytes. I fine most postings on the Internet using BlockSize. It gets a little confusing when I find two ways of returning the same result.
[IV]
aes.IV = keyGen.GetBytes(aes.BlockSize / 8);  // BlockSize(default 128) / 8 = 16
- OR -
aes.IV = keyGen.GetBytes(16);
[Key]
aes.Key = keyGen.GetBytes(aes.KeySize / 8); // BlockSize(default 256) / 8 = 32
- OR -
aes.Key = keyGen.GetBytes(32);

Note: I experimented by encrypting a string message using aes.KeySize/8 and successfully decrypted using GetBytes(32)...
I wasn't sure if there is an advantage....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks :)