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 256bit keysall 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.


