Hi all,
I wrote a small application to encrypt files being part of another proces. It is not for real security reasons but more so that users cannot change things in case they open the file.
I would like to "automate" this encryption by adding an extra batch line in another batch file which is already part of the process.
So I would like the application to accept input from a CMD window. Something like this :
START "" encrypt.exe %cd%\lists\file.txt
or
START C:\Program Location\encrypt.exe file.txt
So in my application I would like the "Readln" to accept the above command and file being 'file.txt'. Or implement something similar that can do this.
This is my working code:
program encrypt;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,
{ you can add units after this }
FileUtil, SysUtils, DCPrc4, DCPsha1;
var
Cipher: TDCP_rc4;
Source, Dest: TFileStream;
Filename, Filepart1, Filepart2: string;
{$R *.res}
begin
Readln(FileName); //<- change or replace this with ...?
if FileExists(ExtractFilePath(ParamStr(0)) + FileName) then
try
Filepart1 := ExtractFileNameWithoutExt(Filename);
Filepart2 := ExtractFileExt(Filename);
Source := TFileStream.Create(ExtractFilePath(ParamStr(0)) + FileName, fmOpenRead);
Dest := TFileStream.Create(ExtractFilePath(ParamStr(0)) + Filepart1 + '1' + Filepart2, fmCreate);
Cipher := TDCP_rc4.Create(nil);
Cipher.InitStr('password', TDCP_sha1);
Cipher.EncryptStream(Source, Dest, Source.Size);
Cipher.Burn;
Cipher.Free;
Dest.Free;
Source.Free;
writeln('File encrypted');
DeleteFile(ExtractFilePath(ParamStr(0)) + FileName);
except
writeln('File IO error');
end else
writeln('file not found');
sleep(1000);
end.
I could not seem to find any on this in the Wiki, or I have missed it.
Is this possible ?
I also could hardcode the filename (which is always the same), copy the file to the place where the encrypt.exe is located, run encrypt.exe and then copy the encrypted file back but this gives more changes on (possible) errors and of course takes longer.
Thanks