Create a Tamper-Proof Hash Code

Problem

You want to create a hash code that can’t be replaced by a malicious user.

Solution

Combine hashing with encryption, either by using a keyed hash code or a digital signature.

Discussion

Hash codes have one obvious limitation: unless you store the hash code in a secure location, there is nothing to stop an attacker from tampering with your data and generating a new hash code that matches the altered data. In this scenario, it would be impossible to detect that any change has taken place. This is a common problem in distributed applications, which use hash codes to validate messages that are sent over a network.

The solution is to create a hash code that an attacker won’t be able to recreate. For example, you can ...

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.