Home > SOA Tips > .NET Developer > Security in .NET 2.0
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

.NET DEVELOPER

Security in .NET 2.0


Pierre Nallet
01.04.2005
Rating: -4.33- (out of 5)


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


The new security components in .NET 2.0 can help you greatly reduce the amount of code you need to write in order to make your applications secure. Security is difficult to get right, and it is a good strategy to leverage the code provided by Microsoft and other security vendors. To that end, .NET 2.0 provides numerous additional types that encapsulate functionality already provided in the base Windows OS., as well a new functionality only available in .NET 2.0. The improvements affect public key cryptography, Windows security, remoting, ASP.NET and Code Access Security. Even if you plan to stick with .NET 1.1 for a while and implement your own security classes, you might want to take inspiration from.NET 2.0 beta.

This article will concentrate on changes to the way certificates and public keys are handled.

Certificates and certificate stores
While it is possible to store certificates in files, it is more convenient and more manageable to have them in a certificate store. Put simply, a certificate store is a database containing certificates. With the new X509Store class, you can open a store and query its certificates using several criteria including subject name and thumbprint. The new X509CertificateEx class is much richer and provides support for checking the certificate revocation list.

The following snippet finds a certificate and prints its status on the console:

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
X509CertificateEx certificate = 
 store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, false)[0];
X509Chain chain = new X509Chain();
...
chain.Build(certificate);
foreach (X509ChainElement e in chain.ChainElements)
{
 foreach (X509ChainStatus s in e.ChainElementStatus)
 {
  Debug.WriteLine(s.Status);
  Debug.WriteLine(s.StatusInformation);
 }
 Debug.WriteLine(e.Information);
}

Public Key Cryptography Standard
In the Pkcs namespace, the new EnvelopedCms and SignedCms classes define ways to create encrypted or signed messages that contain a reference to the certificate used. As a result, processing this message is much easier because you don't have to locate the key yourself.

For example, to encrypt a message, you simply specify the content to protect and the certificate to use.

ContentInfo contentInfo = new ContentInfo(stuffToEncrypt);
EnvelopedCms envelopedMessage = new EnvelopedCms(contentInfo);
CmsRecipient recipient = 
 new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, 
 recipientCertificate);
envelopedMessage.Encrypt(recipient);
byte[] encryptedBytes = envelopedMessage.Encode();

Decrypting the message is effortless because you don't have to specify a key; the framework finds it automatically in the appropriate store based on the embedded serial number.

envelopedMessage = new EnvelopedCms();
envelopedMessage.Decode(encryptedBytes);
byte[] decryptedBytes = envelopedMessage.ContentInfo.Content;
foreach (RecipientInfo r in envelopedMessage.RecipientInfos)
{
 Debug.WriteLine("The message was sent for " + 
  r.RecipientIdentifier.Value +  (r.RecipientIdentifier.Type));
}

In addition, the Xml cryptography namespace has been improved to the level provided by the web services enhancements.

The rest of this article discusses .NET 2.0 enhancements to support for accounts, security identifiers, object level security, data protection API, and secure communication. Read it at The ServerSide.NET.

Pierre Nallet is a software consultant in the San Francisco area. He specializes in all areas of the .NET platform. He has experience in data access, object-oriented programming, component architecture, and compiler technology. He is the author of OLE DB Consumer Templates: A Programmer's Guide published by Addison-Wesley. He is also the creator of XC#, an extensible C# compiler.


Rate this Tip
To rate tips, you must be a member of SearchSOA.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
.NET Developer
Programming Indigo
DataSets and Web services don't mix
Tracking down managed memory leaks
Handling exceptions in .NET
.NET Compact Framework graphics
The Data Access Application Block
A great .NET resource: .Net2TheMax
Delegates vs. interfaces in .NET
Project structure best practices
Working with PDFs in a .NET environment

Microsoft .NET Web services
New SOA tools for Microsoft server
Yahoo proxy fight looms
New Microsoft site for architects
LAMP coders go hybrid route
Silverlight shines on bank RIAs
Microsoft fights on for Yahoo
New Microsoft language for SOA?
Ballmer details software-plus-services
Microsoft/Yahoo could rock Web services world
SOA needs information management
Microsoft .NET Web services Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Common Language Infrastructure  (SearchSOA.com)
Visual J#  (SearchSOA.com)

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.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




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