ARTICLE

How to use VB.NET encyption?

Posted by Sapna Articles | Visual Basic Language July 05, 2010
In this article will see the use of cryptography using encryption method in VB.NET.
 
Reader Level:

Cryptography is used to protect data and has many valuable uses. It can protect data from being viewed, modified, or to ensure the integrity from the originator. Cryptography can be used as a mechanism to provide secure communication over an unsecured network, such as the Internet, by encrypting data, sending it across the network in the encrypted state, and then the decrypting the data on the receiving end.

Encryption Components

Encryption involves the use of a cryptography algorithm combined with a key to encrypt and decrypt the data. The goal of every encryption algorithm is to make it as difficult as possible to decrypt the data without the proper key.


Determining Your Key Length

The .NET encryption routines expect the keys that you use to be a particular size. For example, the DES (Data Encryption Standard) function wants a key to be 64 bits long, while the Rijndael algorithm wants 128-, 192-, or 256-bit keys-all other things being equal, the longer the key, the stronger the encryption. So if you decide to use an algorithm other than DES, you can find out which key sizes it permits by querying the LegalKeySizes property. You can get the MinSize (the smallest key size permitted), the MaxSize (the largest), and the SkipSize (the increment). SkipSize indicates any sizes available between the minimum and maximum sizes. For instance, the SkipSize for the Rijndael algorithm is 64 bits.

You can use the following code to find out the key sizes:

Imports System.Security.Cryptography 
  Module Module1 
     Sub Main()
          Dim des As New DESCryptoServiceProvider()  
          Dim fd() As KeySizes
          fd = des.LegalKeySizes() 'tells us the size(s), in bits
 
          MsgBox("minsize = " & fd(0).MinSize & Chr(13) & "maxsize = " & fd(0).MaxSize 
            & Chr(13) & "skipsize = " & fd(0).SkipSize)
      End Sub
   End Module

If you run this code, you'll get 64, 64, 0. But if you change the declaration to
TripleDESCryptoServiceProvider(), you'll get 128, 192, 64.

 

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor