O'Reilly logo

Visual Basic 2005 Cookbook by Tim Patrick, John Clark Craig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. Cryptography and Compression

Introduction

In today’s world, security is an increasingly important part of development requirements. Visual Basic 2005 and the .NET Framework provide advanced and well-established encryption libraries. This chapter provides recipes for some of the basic tasks you may need to become more familiar with, such as encrypting data files, handling passwords securely, and so on. Closely related to encryption is the science of compression, so some of these recipes also cover this subject.

16.1. Generating a Hash

Problem

You want to hash a string to create a unique, repeatable identifier. This can be used to determine if a string has been altered in any way, to identify a password without revealing the actual password, and to convert a string of any length to a unique fixed-length key for cryptographic algorithms.

Solution

Sample code folder: Chapter 16\Cryptography

Use the .NET Framework’s cryptographic services to generate an industry-standard hash of your data.

Discussion

A hash is like a one-way encryption. There’s no way to recover an original string given its hash value. In fact, it’s technically possible for more than one string to return the exact same hash value, although the odds are against this ever happening in the time allotted for the unfolding of the universe. The MD5 hash used in this recipe returns a 16-byte value, and a quick calculation shows there are over 3 x 1038 unique combinations of 16 bytes. If you were to check through all the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required