import java.io.*;
import java.security.*;
import java.util.* ;
import java.sql.*;

class Digest{
    public static long getCurrentTime()
    {
	java.util.Date date=Calendar.getInstance().getTime();
	Timestamp a=new Timestamp(date.getTime()); 
	long currentTime=Calendar.getInstance().getTimeInMillis();
	return currentTime;
    }

    public static void main ( String[] args){
        if (args.length != 1) {
            System.out.println("Usage: Digest nameOfFileToSign");
	}
	else try{
	    MessageDigest MD = MessageDigest.getInstance("MD5");
	    MessageDigest SHA = MessageDigest.getInstance("SHA-1");

	    File fileName= new File(args[0]);
	    FileInputStream inputFile=new FileInputStream(fileName);
	    int len= (int)fileName.length();
	    byte[] buffer= new byte[len+1];

	    byte[] hashSHA = new byte[10];//>160bits
	    byte[] hashMD5 = new byte[10];//>128bits
	    
	    if(inputFile.read(buffer)!=len)
		System.out.println("file is corrupt");

	    long start=getCurrentTime();
	    hashSHA=SHA.digest(buffer);
	    long end=getCurrentTime();

	    long timeSHA= end-start;

	    hashMD5=MD.digest(buffer);
	    start=getCurrentTime();
	    long timeMD5=start-end;

	    inputFile.close();
	    //	    fileName.close();
	
	    
	    System.out.println("MessageSize(bytes)==> "+ len+"\tMD5(ms)==> "+timeMD5+"\tSHA(ms)==> "+timeSHA);
	}
	catch (Exception e) {
            System.err.println("Caught exception " + e.toString());
	}
    }
}
