Symmetric encryption uses a single shared, secret key to encrypt and decrypt data. Secret key encryption is also called symmetric encryption because the same key is used for encryption and decryption. Anyone that has the key can decrypt the data, which makes protection of the key vital. Private-key encryption is much faster than public-key encryption which makes it ideal for use on large streams of data. However, in real-world operations, public-key encryption is used in conjunction with private-key encryption in order to transmit the private key to the other party.
This sample shows you how to use Rijndael or TripleDES to encrypt and decrypt text files that you can browse for and load into a TextBox. When "Advanced" is checked the key is not generated and set automatically but is rather derived from a password that has been "salted" (see the code comments for more on "salt"). Moreover, the salt and initialization vector (IV) are persisted unencrypted to a .dat file. In this way you can see how you would securely send a document to someone: The encrypted document could be sent over an unsecure wire, and the .dat file and password could be transferred securely using assymetric (or, public key) encryption. (The latter type of encryption is the most secure form of encryption, but it takes much longer to process. This is why it is typically used for small items like a secret key, salt/IV file, password, etc.).
Instead of creating a key.dat file you can write the salt and IV to the encrypted document as unencrypted leading text. When decrypting, simply read the salt and IV from the encrypted document as you would from the .dat file. In this way only the encrypted document and the password are needed.
Microsoft Visual Studio.NET Professional or greater.
Windows XP or Windows 2000.
Simply press F5.