28.3. Applying Cryptography

So far, you have seen the principles of cryptography and how they are achieved through the use of hashing, encryption, and signing algorithms. In this section, you'll walk through a sample that applies these algorithms and illustrates how the .NET Framework can be used to securely pass data between two parties.

28.3.1. Creating Asymmetric Key Pairs

Begin with a new Visual Basic Windows Forms application and divide the form into two vertical columns. You can do this using a TableLayoutPanel with docked Panel controls. Into each of the two vertical columns place a button, btnCreateAsymmetricKey1 and btnCreateAsymmetricKey2 respectively, which will be used to generate the asymmetric keys. Also add two textboxes to each column, which will be used to display the private and public keys. The textboxes in the left column should be named TxtPublicKey1 and TxtPrivateKey1, and the textboxes in the right column should be named TxtPublicKey2 and TxtPrivateKey2. The result should be something similar to Figure 28-1. For reference, add a name label to each of the vertical panels.

Figure 28.1. Figure 28-1

Double-clicking each of the buttons will create event handlers into which you need to add code to generate an asymmetric key pair. In this case use the RSACryptoServiceProvider class, which is an implementation of the RSA algorithm. Creating a new instance of this ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.