Important alert: (current site time 7/15/2013 8:35:25 AM EDT)
 

winzip icon

AES - Advanced Encryption Standard

Email
Submitted on: 2/24/2005 12:22:30 PM
By: Philip Pierce  
Level: Advanced
User Rating: By 4 Users
Compatibility: C#, VB.NET
Views: 57905
(About the author)
 
     AES is the new encryption standard being used in smart chips, cellphones, and database encryption. It's fast and secure, and expected to become more widely used in the following months. Unfortunately, .NET does not include AES in it's encryption library, so you will need to implement your own class. The original idea for this class came from: http://msdn.microsoft.com/msdnmag/issues/03/11/AES. The author of this article had made a class available which does the actual AES encryption, however, the class wsa limited in what could be encrypted. I took the original class and modified it to allow the user to encrypt strings, to send a string password, and to encrypt blocks of data larger than 16 bytes.
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 21 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/24/2005 6:07:48 PM

Ummm .NET DOES INCLUDE AES...
AES is Rijndael, .NET has two namespaces, Rijndael and RijndaelManaged that you can do to use AES!
(If this comment was disrespectful, please report it.)

 
2/24/2005 6:17:22 PMPhilip Pierce

No, you are not correct. AES is not Rijndael. They are sepeate algorithms for encryption. The MSDN article explains it like this:
"In late 1999, the Rijndael (pronounced "rain doll") algorithm, created by researchers Joan Daemen and Vincent Rijmen, was selected by the NIST as the proposal that best met the design criteria of security, implementation efficiency, versatility, and simplicity. Although the terms AES and Rijndael are sometimes used interchangeably, they are distinct. AES is widely expected to become the de facto standard for encrypting all forms of electronic data including data used in commercial applications such as banking and financial transactions, telecommunications, and private and Federal information."
(If this comment was disrespectful, please report it.)

 
3/17/2005 12:03:59 AM

The difference between AES and Rijndael is that AES has a fixed block size of 128 bits and a key size of 128, 192, or 256 whereas Rijndael can be specified with key and block sizes in any multiple of 32 bits, with a minimum of 128 bits and a maximum of 256 bits. VB.net Rijndael has a Skip Size of 64 bits. Here is a few lines of code to get key sizes:

'create the Rijndael Crypto object
Dim rmRijndael As New RijndaelManaged

Dim KS() As KeySizes
KS = rmRijndael.LegalKeySizes()

MsgBox(
(If this comment was disrespectful, please report it.)

 
3/17/2005 12:09:33 AM

Dim rmRijndael As New RijndaelManaged
Dim KS() As KeySizes
KS = rmRijndael.LegalKeySizes()
MsgBox("Minsize = " & KS(0).MinSize _
& Chr(13) & _
"Maxsize = " & KS(0).MaxSize _
& Chr(13) & _
"Skipsize = " & KS(0).SkipSize)
(If this comment was disrespectful, please report it.)

 
3/22/2005 5:55:48 AM

It will be great if the actual encrypt/ decrypt of a value can be shown by allowing inputs through a winform..
I tried this sample by initially converting it to VB.Net and then calling the instance of this class.
I not getting as to how should i pass the values for encrypt/decrypt.
The constructor initial accepts the
(If this comment was disrespectful, please report it.)

 
3/22/2005 5:58:13 AM

can u please show the encrypt/decrypt functionality in actual work?
i tried this by putting 3 textboxes and passing the values to the instance but could not achieve the results
(If this comment was disrespectful, please report it.)

 
7/14/2006 4:41:06 AMmannelfo

there is an error encrypting/descypting string long a number of digit divisor of 16 (and long less then 16 digit). I resolved the problem simply putting this codeline in the function "GetArraySize" (first of all):
if (Arraylen <= 8) ArrayLen = 16;
(If this comment was disrespectful, please report it.)

 
11/20/2007 10:28:39 AMIvan Shepperd

I believe there is an problem when the length of the string to encrypt is evenly divisible by 16 AND is > 32 (e.g. 32, 48, 64, 80...). If you encrypt something like "0123456789abcdef01234567890abcedef" (32 bytes) it appends 16 extra zeros to the encrypted output which then decrypts incorrectly.
The fix appears to be in GetArraySize. there is a line
if ( (BlockSize % ArrayLen) == 0)
which is trying to determine if the length of the data is evenly divisible by 16. The dividend and divisor are reversed. It should read
if ((ArrayLen % BlockSize) == 0)
(If this comment was disrespectful, please report it.)

 
2/23/2008 5:46:25 AMPSF

In NetFrameWork 3.5:
http://msdn2.microsoft.com/en-us/library/bb352381.aspx
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.