Solved

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

Posted on 2004-09-13
6
873 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
[X]
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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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