
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Encrypting and Decrypting a File
|
957
If the SaveSensitiveData method is used to save the following text to a file:
This is a test
This is sensitive data!
the ReadSensitiveData method will display the following information from this same
file:
---------- Encrypted Data ---------
????????????????????????????????????????
---------- Encrypted Data ---------
---------- Decrypted Data ---------
This is a test
This is sensitive data!
---------- Decrypted Data ---------
Discussion
Encrypting data is essential to many applications, especially ones that store informa-
tion in easily accessible locations. Once data is encrypted, a decryption scheme is
required to restore the data back to an unencrypted form without losing any infor-
mation. The same underlying algorithms can be used to authenticate the source of a
file or message.
The encryption schemes used in this recipe are TripleDES and Rijndael. The reasons
for using Triple DES are:
• TripleDES employs symmetric encryption, meaning that a single private key is
used to encrypt and decrypt data. This process allows much faster encryption
and decryption, especially as the streams of data become larger.
• TripleDES encryption is much harder to crack than the older DES encryption.
• If you wish to use another type of encryption, this recipe can be easily ...