Home > Microsoft .Net Development Tips > Application Testing and Security > The System.Security.Cryptography namespace
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

APPLICATION TESTING AND SECURITY

The System.Security.Cryptography namespace


Ed Tittel
03.11.2003
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!

Every now and then I stumble across an obvious reference that's just too good to ignore, and end up asking myself "How have I missed out on this for so long?" That's my story (and I'm sticking to it fervently) where Visual Studio Magazine is concerned. The March 2003 issue contains a wealth of treasures for VS aficionados, including a 5-page story by Travis Vandersypen entitled "Sure .NET Apps with Cryptography" that I'm abstracting to less than 20% of its original heft for the benefit of this tip.

Microsoft offers a set of classes to support a broad and fairly sophisticated range of cryptography services within the .NET Framework. Encased within its offerings, you'll find both private key encryption and public/private key encryption algorithms. Because these are also known as symmetric and asymmetric encryption algorithms, when the System.Security.Cryptography namespace provides classes for each one, it calls them SymmetricAlgorithm and AsymmetricAlgorithm respectively.

As far as the .NET Framework's symmetric encryption algorithms go, they include the following:

  • Data Encryption Standard (DES): in DES a 56-bit key is applied to 64-bit blocks of data, run in multiple modes and using 16 rounds or operations. Now somewhat outmoded (today's processors can break it too easily for it to be deemed entirely safe), it's usually employed three times in a row to strengthen its results (see Triple DES below). Look up DES or Triple DES on whatis.com for more info.
  • Ron's Code 2 (RC2, "Ron" refers here to Ron Rivest, the R in RSA Technologies, and the author of numerous well-known and -used encryption algorithms): A variable key-size block cipher designed to be faster than DES and to work as a drop-in replacement for DEC. By varying the key size, it can be made more (>56 bits) or less (<56 bits) secure than DES. Before export conditions were lifted, RC algorithms were easier to export than the more tightly controlled DES technologies. Check out the RC2 entry in RSA's Techniques in Cryptography FAQ for more info.
  • Tripe DES (iterates DES algorithm thrice as part of basic operation): a stronger form of DES encryption widely used for volatile information or message traffic.

Each of these three serves as a super class for a .NET managed class. For each algorithm, you must define an encryption key and an initialization vector to make the associated encryption routines work. Suffice it to say that the key provides the mechanism for encryption and decryption (that's what makes it symmetric) and the initialization vector helps to randomize encryption so that two identical blocks of text won't ever encrypt the same way (that's a peachy way to break a code, and works better the longer the text block might be, so it's wise to avoid this by design whenever possible).

Working with private-key classes is relatively straightforward within the .NET Framework:

  • Instantiate the managed class.
  • Set an initialization vector.
  • Establish an encryption key.
  • Use the CryptoStream class to move information through an encryption or decryption routine.

In my next tip, I'll provide some code examples that do this very thing, so you can move from the abstract to the hands-on. In the meantime, check out the SymmetricAlgorithm and AsymmetricAlgorithm namespaces.


Ed Tittel is a principal at LANWrights, Inc. a wholly-owned subsidiary of iLearning.com, where he writes and teaches on a variety of subjects, including markup languages, development tools, and IT certifications. Contact Ed via e-mail at etittel@lanw.com.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Application Testing and Security
Test-driven development in .NET yields complete unit test coverage
How to write installers in Vista that work correctly under UAC
How to elevate programs' privileges correctly using Vista's UAC
Internet Explorer 8 beta's development tools add source visualizations
Microsoft previews new features in Visual Studio 2010
Advanced Windows Debugging Book Chapter and Podcast
Book excerpt: Advanced Windows Debugging
Book excerpt: Pragmatic unit testing in C# with NUnit
Security interoperability with .NET/WSE and WebLogic Workshop 8.1
How to avoid regression bugs while adding new features

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts