tags:

views:

411

answers:

2

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?

A: 

This might help
http://www.naterice.com/articles/66

Tester101
That solution requires you already have md5.exe, which defeats the purpose of using VBScript.
Tmdean
A: 

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.

orip