03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

602 ❘ CHAPTER 27 Cryptography<br />

This chapter describes only a few of the most useful cryptographic methods provided by the .NET<br />

Framework. Those include generating cryptographically secure random numbers, symmetric encryption,<br />

and asymmetric encryption.<br />

This chapter explains only how to use .NET Framework tools to perform those tasks, but it<br />

should be enough to get you started with cryptography. Unfortunately, there isn’t room here to<br />

explain all the methods for performing even those limited tasks or to explain how those methods<br />

work. See a book about cryptography (such as Bruce Schneier’s book) for details about how some<br />

of these algorithms work.<br />

Leisure Reading<br />

The history of cryptography contains truly remarkable stories involving spies and<br />

counterspies, ingenious contraptions, breaking unbreakable codes, and using clever<br />

artifice to convince the enemy that its code is secure even after it’s broken. If you<br />

have the time, it makes fascinating reading.<br />

Cryptography was originally used to send messages from one person to another securely. Modern<br />

cryptography has expanded to include other sorts of secure communication. The following section<br />

describes some of the operations that modern cryptographic programs perform. The sections after<br />

that explain some of the cryptographic tools you can use in your <strong>C#</strong> programs.<br />

Cryptography Namespaces<br />

The System.Security.Cryptography namespace includes cryptographic classes.<br />

To make using these classes easier, you may want to include the following using<br />

directive in your code.<br />

using System.Security.Cryptography;<br />

Cryptographic Operations<br />

The following list describes some of the most common cryptographic operations.<br />

➤➤<br />

➤➤<br />

Symmetric key encryption (private key encryption)—This technique uses a secret key<br />

to encrypt and decrypt messages. You use the key to encrypt a message. You then send the<br />

result to someone else who knows the key. That person uses the key to decrypt the message.<br />

Asymmetric key encryption (public key encryption)—This technique uses two keys, a public<br />

key and a secret key, to encrypt and decrypt messages. Everyone knows the public key that is<br />

used to encrypt messages. Only those who know the secret key (typically a single person) can<br />

decrypt the messages. (This is sort of like a mail slot in a door. Anyone can slip a message<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!