Solved

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

Posted on 2004-09-13
6
869 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

776 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