Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

What is the Input vs. Output size in Rijndael Managed cryptography

Posted on 2004-09-13
6
871 Views
Last Modified: 2013-12-03
If I encrypt an X byte string using Rijndael Managed cryptography in C#, what will the output string size be?  From my reading, I would think it would be in 16 byte chunks, because the default blocksize is 128 (bits, I think), but when I encrypt a 16 byte string, I get 44 bytes out.  I did not write the encryption/decryption function I am using, the code is shown below.  Does the size change have to do with the base64 stuff, which I am not clear on either?  Once upon a time in life I thought I knew something, but lately...

public static string Encrypt(string inStr)
{
  System.Security.Cryptography.RijndaelManaged rij = new System.Security.Cryptography.RijndaelManaged();
  rij.Key = thisKey;
  rij.IV = thisIV;
  byte[] inByte = System.Text.Encoding.UTF8.GetBytes(inStr);
  byte[] outByte = rij.CreateEncryptor().TransformFinalBlock(inByte, 0,inByte.Length);
  string encryptStr = Convert.ToBase64String(outByte);
  return encryptStr;
}
public static string Decrypt(string inStr)
{
  System.Security.Cryptography.RijndaelManaged rij = new System.Security.Cryptography.RijndaelManaged();
  rij.Key = thisKey;
  rij.IV = thisIV;
  byte[] inByte = Convert.FromBase64String(inStr);
  byte[] outByte = rij.CreateDecryptor().TransformFinalBlock(inByte, 0,inByte.Length);
  string decryptStr = System.Text.Encoding.UTF8.GetString(outByte);
  return decryptStr;
}

Thank you.

0
Comment
Question by:kevinmackenzie
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12050559
the base64 has a whole lot to do with it ... base64 adds significant size overhead

the encryption also adds a bit but not as significant as the base64.
0
 

Author Comment

by:kevinmackenzie
ID: 12050710
Thanks.  Can you explain the two overheads so that I can predict them?  I will go study base64, but I can find NOTHING that describes the overhead for Rijndael...

Kevin
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12050870
base64 is roughly 3 times larger.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:kevinmackenzie
ID: 12050909
If you or anyone else can point me to a reference that describes the overhead for base64 and another reference for rijndael, that would make this question answered.

I appreciate the effort, but "roughly" does not get close enough to an answer.

Thanks,

Kevin
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 12051156
sorry its roughly 33% and here is why http://email.about.com/cs/standards/a/base64_encoding.htm you cannot go past roughly because there is header info and it works in blocks of 3.

for a large file no biggie but on say 10 bytes thats a big difference.
0
 

Author Comment

by:kevinmackenzie
ID: 12051326
Thank you, I will split the points, I am still hoping for a reference or answer on the Rijndael overhead.

Kevin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question