Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Encrypting and Decrypting a File
|
953
This method displays:
decryptedString: MyPassword
There does not seem to be any problem with using escape sequences such as \r, \n,
\r\n,or\t in the string to be encrypted. In addition, using a quoted string literal,
with or without escaped characters, works without a problem:
@"MyPassword"
See Also
See Recipe 17.3; see the “System.Cryptography Namespace,” “MemoryStream
Class,” “ICryptoTransform Interface,” and “RijndaelManaged Class” topics in the
MSDN documentation.
17.3 Encrypting and Decrypting a File
Problem
You have sensitive information that must be encrypted before it is written to a file
that might be in a nonsecure area. This information must also be decrypted before it
is read back in to the application.
Solution
Use multiple cryptography providers and write the data to a file in encrypted format.
This is accomplished in the following class, which has a constructor that expects an
instance of the
System.Security.Cryptography.SymmetricAlgorithm class and a path
for the file. The
SymmetricAlgorithm class is an abstract base class for all crypto-
graphic providers in .NET, so you can be reasonably assured that this class could be
extended to cover all of them. This example implements support for TripleDES and
Rijndael. It is easily be extended for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata