Verify That Data Hasn’t Changed

Problem

You want to ensure that a file or combination of data files cannot be undetectably altered.

Solution

Use a HashAlgorithm class to create a hash code based on the data, and store this hash code to use for future comparisons.

Discussion

Encryption prevents malicious users from reading your data, but it doesn’t stop them from tampering with it. Instead, you need a way to validate data and detect whether it has been altered. This is the role played by hash codes.

A hash code algorithm generates a small (typically about 20-byte) binary fingerprint for any data that can be represented as a sequence of bytes. Hash codes are cryptographically secure, which means that it’s extremely difficult for a malicious user to create ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.