Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

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

Rate me:
Please Sign up or sign in to vote.
4.54/5 (19 votes)
4 Jul 200412 min read 149.3K   3.7K   56  
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.

CHANGES

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

EOF

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.

License

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


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions