Encrypting and Decrypting Data by Using a Password

Encrypting and decrypting data is achieved by calling CryptEncrypt and CryptDecrypt. These two functions require as an input a handle to a key that is used for encrypting or decrypting the data. The easiest way to get a handle to a key is to derive one using a password. This section discusses how to perform encryption and decryption by deriving the keys with passwords.

The simplest way to perform encryption and decryption with a password is to use the ManagedCryptoAPI class to do all of the work for you. To encrypt data using a password as the encryption key, follow these steps:

Acquire an instance of the ManagedCryptoAPI class.
Acquire byte arrays for text to encrypt and acquire the text ...

Get Microsoft® .NET Compact Framework Kick Start now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.