Question

On a page that automatically lists several small files (~100-500kb) that are contained in a specific folder, is there a way using VBScript to automatically generate MD5 hashes of each file and display it on the page?

Cliff notes: Can I generate an MD5 hash of a file on the server machine?

Was it helpful?

Solution

If the VBScript is client-side you have a problem.

If it runs server-side then it's easy (as long as the web server has read rights).

Simple solution - for each file get its MD5 hash by:

  1. Read the file into memory
  2. Calculate the MD5 hash with System.Security.Cryptography.MD5CryptoServiceProvider
  3. Convert to hex with System.BitConverter.ToString(array).Replace("-","")

A (much) better solution would be to read the file in blocks and feed it to MD5CryptoServiceProvider, because loading an entire big file into memory is not the best thing in the world.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top