Encrypting the string will prevent users from being able to read and decipher the information. If you have a string you want to be able to encrypt and decrypt — perhaps a password or software key — which will be stored in some form accessible by users, such as in a file, the registry, or even a field, that may be open to attack from malicious code. The sample code in this article, CryptoString class, contains two static methods to encrypt and decrypt a string and two static properties to retrieve the generated key and inititialization vector (IV—a random number used as a starting point to encrypt data) after encryption has occurred.

This class uses the Rijndael algorithm to encrypt and decrypt a string. This algorithm is found in the System.Security.Cryptography.RijndaelManaged class. This algorithm requires a secret key and an initialization vector; both are byte arrays. A random secret key can be generated for you by calling the GenerateKey method on the RijndaelManaged class. This method accepts no parameters and returns void. The generated key is placed in the Key property of the RijndaelManaged class. The GenerateIV method generates a random initialization vector and places this vector in the IV property of the RijndaelManaged class.
Read the rest of this entry »

Popularity: 27% [?]