Solved

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

Posted on 2004-09-13
6
865 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
Comment Utility
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
Comment Utility
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
Comment Utility
base64 is roughly 3 times larger.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kevinmackenzie
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you, I will split the points, I am still hoping for a reference or answer on the Rijndael overhead.

Kevin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now