0

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?

Travis
  • 12,001
  • 8
  • 39
  • 52

1 Answers1

1

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
  • 73,323
  • 21
  • 116
  • 148
  • Not a problem computing the MD5 on the client-side. See http://stackoverflow.com/questions/10198690/how-to-generate-md5-using-vb-in-classic-asp/10198875#10198875 – Cheeso Apr 17 '12 at 22:21
  • @Cheeso - agreed that's it possible to compute MD5 on the client side, but the files need to be downloaded to the client by the VBScript code. I'm not sure that's what the OP had in mind. – orip Apr 18 '12 at 07:29