Click here to Skip to main content
13,353,706 members (60,902 online)
Click here to Skip to main content


56 bookmarked
Posted 27 Jun 2004

A CBC Stream Cipher in C# (With wrappers for two open source AES implementations in C# and C)

, 4 Jul 2004
An article on .NET cryptography
A CBC Symetric Cipher implementation in C#

(Plus an implementation of Advanced Encryption Standard (AES) in .NET C# and C)


Q: .NET already implements Rijndael in managed code why another implementation in C#?

A: .NET System.Security.Cryptography is quite good and its underlying Crypto API is great, but it lacks an important feature: Transparency. The only option you have is to trust it. The stream cipher here and the two AES libraries comes with complete source code.

Q: I checked the code. It does not implement any of the .NET System.Security.Cryptography interfaces. This makes it not suitable to use with existing code.

A: My intention was that this code had as little interaction with .NET namespaces as possible. The code can be easily ported to a not .NET language. This makes it very usable. The interface is so simple that integrating this code with the rest of .NET encryption should not be a problem.

Q: Sounds too good to be true, are there any drawbacks?

A: The C# AES implementation is slower that .NET (CryptoAPI) Rijndael implementation. However it is functionally the same as the C implementation. Use the C# wraper of the C aesc.dll in code. Use the pure C# implementation just to have an idea what the code does and to run verification tests.

Q: Any other issues I must know before using this code?

A: The original C# Aes.cs implementation is by James McCaffrey, and appeared in the MSDN magazine. Read EULA.doc for copyright issues. The C implementation is free for any kind of usage and is by Brian Gladman. The �*.cs� files have the names of the authors. I wrote only the CBC stream cipher library to make the code really usable in practice.

Q: How can I get started?

A: To get started see: cs\aes-example.cs

Q: Can I use your stream cipher with another block cipher?

A: Yes, and it is very easily. You need only to implement IBlockCipher.cs. See CAes.cs for an example.


02-JUL-2004 (a) Modified Decrypt() to fail silently
            (b) Removed some constans from code to make it generic

30-JUN-2004 (a) Modified padding to be compatible with .NET SymmetricAlgorithm


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Germany Germany
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 5 Jul 2004
Article Copyright 2004 by vcepa
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid