ASP - Encrypt a File using AES algorithm in Classic ASP

Asked By Luis on 23-Mar-10 05:26 PM

Hello, I need to build 2 procedures in ASP 3.0.  One procedure to encrypt a file, and the other one to decrypt the file.  The function must accept the input file as a parameter, locate the file in the client hard drive, and then encrypt it, using the AES algorithm.

 


I already have the AES library and the functions -->

Function AESEncrypt(sPlain, sPassword)
Function AESDecrypt(sCypher, sPassword)

I'm using them as follows-->

Sub EncriptarArchivo(archivoInput,archivoOutput,password)
   const ForReading = 1
   const TristateFalse = 0
   dim strSearchThis
   dim objFS
   dim objFile
   dim objTS
  
   set objFS = Server.CreateObject("Scripting.FileSystemObject")
   set objFile = objFS.GetFile(Server.MapPath(archivoInput))
   set objTS = objFile.OpenAsTextStream(ForReading, TristateFalse)
  
   strSearchThis = objTS.Read(objFile.Size)
   strPass = trim(password)
   strCadena = AESEncrypt(strSearchThis, strPass)

It works OK with SMALL files, but with BiGGeR files, I get a TimeOut response from the Server.
How could I solve that problem?

Hesham Amin replied to Luis on 23-Mar-10 07:13 PM
For very large files. You should make the encryption a separate process (a windows service for example).
Or you can increase the script timeout
Server.ScriptTimeout=100 '100 seconds
Super Man replied to Luis on 24-Mar-10 01:13 AM

Server.ScriptTimeout

 

This value indicates how long, in seconds, the server will let an ASP script run until it is stopped by the server. The default value is 90 seconds. An error occurs if a script requires more time than this value allows but you can override the default. To change this value in an individual ASP page, you can add this code:

 

 <%    Server.ScriptTimeout = 180 %>

Luis replied to Super Man on 24-Mar-10 10:38 AM

I can increase the Server.ScriptTimeout, but still it is taking too much time to process the file.
I need to find out a way to make it works FASTER.

Maybe the way I'm reading the file, it is not the BEST way, or maybe I should use a different approach to Encrypt the data?