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.
964
|
Chapter 17: Security
This method first removes the hash value from the end of the StringWithHash vari-
able. Next, a new hash is calculated using the string portion of the
StringWithHash
variable. These two hash values are compared. If they are the same, the string has
been received, unmodified. Note that if you change the hashing algorithm used, you
must change it in both this method and the
CreateStringHash method. You must also
change the HASH_LENGTH constant in the
TestReceivedStringHash method to an
appropriate size for the new hashing algorithm. This number is the exact length of
the base64 representation of the hash value, which was appended to the string.
See Also
See the “SHA256Managed Class,” “Convert.ToBase64String Method,” and “Convert.
FromBase64String Method” topics in the MSDN documentation.
17.6 Wrapping a String Hash for Ease of Use
Problem
You need to create a class to isolate other developers on your team from the details
of adding a hash to a string, as well as the details of using the hash to verify if the
string has been modified or corrupted.
Solution
The following classes decorate the StringWriter and StringReader classes to handle a
hash added to its contained string. The
WriterDecorator and StringWriterHash
classes allow the StringWriter class to be decorated
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